On the Rails console, assigning an object to a variable can lead to this strange error (without stacktrace):
irb > recipient = Recipient.find(123)
Traceback (most recent call last):
TypeError (nil can't be coerced into Integer)
irb > recipient
#<Recipient ...
The error is only in the output – the assignment is working. It only occurs when using the --nomultiline
option, and thus
only with IRB 1.2.0+ and before Ruby 3
Show archive.org snapshot
. Also, it depends on the value of the assignment – not every Recipient
(in this example) will trigger it.
Solution
Its cause is in
the reline gem
Show archive.org snapshot
, and the issue is fixed in reline 0.2.0. So either gem install reline
, or in projects with Bundler:
gem 'reline', '>= 0.2.0' # Fixes TypeError in Rails console
Posted by Dominik Schöler to makandra dev (2023-11-07 12:15)