Rails 3, passing local variable to partial [duplicate] Rails 3, passing local variable to partial [duplicate] ruby-on-rails ruby-on-rails

Rails 3, passing local variable to partial [duplicate]


I actually just use this syntax in Rails 3:

render "a_partial", :a_local_variable => whatever, :another_variable => another


This should work:

<%= render :partial => "info", :locals => { :img_style => "original" } %>

With this partial:

# infos/_info.html.erb<%= image_tag(info.image.url, :class => img_style),  info %>

However if you are calling the partial wrong then try this as the partial:

# infos/_info.html.erb<%= image_tag(info.image.url(img_style)),  info %>


I've spent several hours on this; in a view, render :partial => ? , :locals => (....}it seems if you first call:

render :partial => ? without a locals hash

and THEN call render :partial => ? with a locals hash the locals hash IS NOT passed to the view.

If the first call includes a locals hash with the same variables set to ''then the second call with REAL values will work.