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

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

Partial: locations/_form.html.erb

1
2
 
Street: <%= location.street %>

Good luck!

3 thoughts on “Passing Variables to a Partial from a View – Ruby on Rails

  1. arss

    I think this is among the most vital info for me. And i am glad reading your article. But want to remark on few general things, The website style is perfect, the articles is really great : D. Good job, cheers

    Reply

Leave a Reply