Home > Ruby on Rails > Ruby on Rails Debugging Quickies

Ruby on Rails Debugging Quickies

I’m learning Ruby on Rails the hard way (modifying an existing project :) ).

What is the first and most basic need in a situation like this?

To be able to print out an object and its contents so you can inspect it, just like “var_dump” and “print_r” do it in PHP.

This is how you do it in RoR:

If you are in a view:

<%= @object.inspect %>
#or
<%= debug @object %>

If you are in a controller:

return render :text => @object.inspect
# or
return render :text => YAML::dump(@object)  

That should do the trick, weeeell … now you know :)

  1. March 18th, 2010 at 19:09 | #1

    me parece genial tio, buen post!

  1. No trackbacks yet.