Write to rails console

freemanoid picture freemanoid · Feb 19, 2013 · Viewed 152.7k times · Source

When I want to try or debug smthing I run rails console and do some stuff there. I can print some text or variables from code by raising exception with raise "blablabla". Question: How I can just write to rails console without exception raising (and obvious breaking code execution) like a simple logger.info "blah"?

Answer

Nobita picture Nobita · Feb 19, 2013

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? :)