Write to rails console
Solution 1:
As other have said, you want to use either puts
or p
. Why? Is that magic?
Actually not. A rails console is, under the hood, an IRB, so all you can do in IRB you will be able to do in a rails console. Since for printing in an IRB we use puts
, we use the same command for printing in a rails console.
You can actually take a look at the console code in the rails source code. See the require of irb? :)
Solution 2:
puts
or p
is a good start to do that.
p "asd" # => "asd"
puts "asd" # => asd
here is more information about that: http://www.ruby-doc.org/core-1.9.3/ARGF.html
Solution 3:
I think you should use the Rails debug options:
logger.debug "Person attributes hash: #{@person.attributes.inspect}"
logger.info "Processing the request..."
logger.fatal "Terminating application, raised unrecoverable error!!!"
https://guides.rubyonrails.org/debugging_rails_applications.html
Solution 4:
In addition to already suggested p
and puts
— well, actually in most cases you do can write logger.info "blah"
just as you suggested yourself. It works in console too, not only in server mode.
But if all you want is console debugging, puts
and p
are much shorter to write, anyway.