I am using nested forms with multiple instances of various of the forms. The
problem I cant figure out is how to maintain state for the select between
postbacks. I am using ''options_from_collection_for_select'' and
in this the
last param is to be the selected value, but given the dynamic nature, the
value is going to depend on the iteration of the form builder. If I manually
force a selected value, it works, so I know this has to be the answer, as if
I do not use this last param, I get no maintained state.
What also gets me is that if I use a manual array rather than
options_from_collection_for_select, i.e. [ [''hr'',1],
[''rbi''],2 ...], rails
maintains the state for me... I guess I could at the controller manually
create this from the model but that is disgusting and counter to why there
would be a helper... So open to suggestions. I have also tried
collection_select with no luck.
<%= s.select :statistic_type_id,
options_from_collection_for_select(StatisticType.all, :id, :name,
selected_value_here),
This is part of the context:
<%= b.fields_for :players do |p| %>
<%= p.label :player_id %>
<%= collection_select :p, :player_id, Player.all, :id, :last_name,
:include_blank => true %><br>
<%= p.fields_for :statistics do |s| %>
<%= s.label :statistic_id %>
<%= s.select :statistic_type_id,
options_from_collection_for_select(StatisticType.all, :id, :name,
selected_value_here), :include_blank => true %>
<%= s.text_field :value %><br>
<% end %>
<% end %>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.