Reputation: 5126
I'm working with a Rails 3.0.20 app and I'm trying to pass a local variable through a partial and it's displaying 'undefined local variable' I've had a look at the other posts on this issue and couldn't fix it.
Here is my call to render the parital
= f.fields_for :current_positions do |builder|
= render :partial => 'current_position_fields', :locals => {:f => builder, :foo => 'hi'}
Here is my partial
%tr.pos_start
%td
= foo
= f.hidden_field :id, class: "pos_id"
= f.label :name, "Position Name"
%td= f.text_field :name
%tr.pos_loc
%td= f.label :location, "Position Location"
%td= f.text_field :location
%tr.pos_end
%td= f.label :year, "Position Year"
%td= f.text_field :year
%td.fields
= link_to_remove_fields "DEL", f
The error message is
undefined local variable or method `foo' for #<#<Class:0x00000008d4a050>:0x00000008d3c590>
If I take the = foo
out of the code everything else works.
Upvotes: 2
Views: 3083
Reputation: 5126
Found my error, I was calling the partial in an application helper as well and not passing on the appropriate local variables.
I found this when I could copy the partial to another name and call that with a variable and it worked.
Upvotes: 7
Reputation: 2653
Try:
=render 'current_position_fields', :f => builder, :foo => 'hi'
Upvotes: 0