dopplesoldner dopplesoldner - 2 months ago 14x
Ruby Question

Rails 4 - passing variable to partial

I am following the Ruby on Rails tutorial and have come across a problem while trying to pass variables to partials.


partial is as follows

<%= gravatar_for user, size: 52 %>
<%= link_to, user %>

I would like to pass in a number for the size value. I am trying as follows without any luck.

<%= render @users, :locals => {:size => 30} %>

Thanks in advance!


You need the full render partial syntax if you are passing locals

<%= render @users, :locals => {:size => 30} %>


<%= render :partial => 'users', :collection => @users, :locals => {:size => 30} %>

Or to use the new hash syntax

<%= render partial: 'users', collection: @users, locals: {size: 30} %>

Which I think is much more readable