Tag Archives: variables

Debugging with Exceptions – Ruby on Rails

Ran into a bit of trouble with a model today, after a bit of a google I came across this technique which helped me solve it:

#Raise exception on object.inspect
raise Object.inspect

#Example 1
raise order.inspect

#Example 2
raise [sub_orders.count].inspect

This simply allows you display variable values as an exception. By placing a few of these throughout your troublesome code you can simulate a fully targeted trace.

Passing Variables to a Partial from a View – Ruby on Rails

Just another one of those things that I find myself needing to do from time to time. Luckily this is all pretty straight forward (thankyou Ruby on Rails!). Assuming your partial is a form in the locations folder and that the variable you’re expecting is location all that you have to do is following:

View: users/show.html.erb

 'locations/form', :locals => { :location => @user.location } %>

Partial: locations/_form.html.erb


Good luck!