Reputation: 10350
Here is code in form.html.erb for partial view. Local var :sid was defined as the id of the record and it should be passed into the partial view standards.html.erb as a local var.
<% @rfq.standards.each do |r| %>
<p><%= render :partial => 'standards', :locals => { :f => f, :sid => r.id } %></p>
<% end %>
Here is the standards partial view:
<%= f.association :standards, :collection => Standard.active_std.all(:order => 'name'), :label_method => :name, :value_method => :id,
:prompt => "Choose std", :label => "standard:", :include_blank => true, :selected => :sid %>
When rendered, standards partial view should render a collection of standards with sid selected. However the code above does not select the standards at all. Tried sid (string) :selected => sid. This causes error saying that sid was not defined.
My question is what's the right way to pass and retrieve a local var in view? Thanks so much.
Upvotes: 1
Views: 530
Reputation: 10350
The problem was caused by the partial standards were not called in each and every place with exactly the same format. In one method (not shown here), the partial standards was called like: render :partial => standards, :locals => {:f => f}
. After adding :sid => 0 as render :partial => standards, :locals => {:f => f, :sid => 0}
, the sid here is passed in successfully.
Upvotes: 1