views:

35

answers:

3

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?

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
oh, actually, can it show on the webpage?
動靜能量
A: 

You can debug in the view: <%= debug @post %>. More info: http://guides.rubyonrails.org/debugging_rails_applications.html

Flavius Stef
+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