Selected option in collection_select()

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 } ) %>

Is this correct? I have tried using :selected in options and html_options.

Thanks

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.