In PHP, CGI, or in RoR's View, we can easily print out debug information. How about in the Controller, how can we just say, print "hello world"
(to the webpage output) and return to continue with the view, or stop the controller right there?
irb - Method called on an object when displayed on the console in Ruby - Stack Overflow.
To help deal with bugs, the standard distribution of Ruby includes a debugger. In order to start the Ruby debugger, load the debug library using the command-line option -r debug. The debugger stops before the first line of executable code and asks for the input of user commands.
In the controller you can:
render :text => @some_object.inspect
But your view won't be rendered.
You could also:
Rails.logger.debug("My object: #{@some_object.inspect}")
and run tail on log/development.log to see the output.
In the view the recommeneded way is:
<%= debug(@some_object) %>
Don't know about print
, but puts
never failed me. Your hello world
will be in console and logs and normal flow will continue.
Did I understand you correctly?
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