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?
views:
35answers:
3
A:
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?
Nikita Rybak
2010-07-27 20:54:42
oh, actually, can it show on the webpage?
動靜能量
2010-07-27 20:58:36
A:
You can debug in the view: <%= debug @post %>
. More info: http://guides.rubyonrails.org/debugging_rails_applications.html
Flavius Stef
2010-07-27 21:01:52
+5
A:
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) %>
codecaster
2010-07-27 21:03:49