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"?
Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias “s” to start the server: rails s. The server can be run on a different port using the -p option. The default development environment can be changed using -e.
In a Rails app, logs are stored under the /log folder. In development mode, the development. log file is used & you see log output on the terminal you're running rails server on.
Ruby has another three methods for printing output. In the example, we present the p , printf and putc methods. The p calls the inspect method upon the object being printed. The method is useful for debugging.
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? :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With