freemanoid freemanoid - 2 months ago 6
Ruby Question

Write to rails console

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 "blah"


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