Ed wrote:> I am trying to use the :selected option of collection_sellect(), and it
> is not working. Here is my code.
>
> <%= collection_select(
> :player, :season_team_id, @season_teams, :id, :color, {},
> { :selected => player.season_team_id }
> )
> %>
I figured out the problem.
I was calling this in a for loop to list each player on the form.
<% for player in @players %>
<%= collection_select(:player, :season_team_id, ... ) %>
<% end %>
I changed my code to this and :selected works.
<% for @player in @players %>
<%= collection_select(
''player[]'', :season_team_id, @season_teams, :id, :color,
{ :selected => @player.season_team_id }
) %>
Does anyone have a resource describing how forms containing collections
work? The Agile book has a small sidebar on the topic, but I''m still
unclear.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---