Created
May 12, 2009 14:19
-
-
Save abloom/110508 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This is the form tag I normally have to do | |
<% #form_for game_player,:url => game_player_path(params[:slug], game_player) do |f| %> | |
#This is what I was trying | |
# This form submits to http://localhost:3000/game_players/update_all, I need the team slug in front | |
<% form_tag (:controller => "game_players", :action => "update_all") do %> | |
<% for game_player in @game_players %> | |
<% fields_for "game_player_#{game_player.id}" do |f| %> | |
<%= f.error_messages %> | |
<%= f.select(:batting_order, [['1', 1], ['2', 2], ['3', 3], ['4', 4], ['5', 5], ['6', 6], ['7', 7], ['8', 8], ['9', 9], ['10', 10], ['11', 11], ['12', 12], ['13', 13], ['14', 14], ['15', 15], ['16', 16], ['17', 17], ['18', 18], ['19', 19], ['20', 20]], {:value => game_player.batting_order}) %></td> | |
<% @player = Player.first(:conditions => ["id = ?", game_player.player_id]) %> | |
<%= @player.name_with_initial %> | |
<% @position = FieldPosition.first(:conditions => ["id = ?", game_player.field_position_id]) %> | |
<%= f.collection_select(:field_position_id, FieldPosition.all, :id, :short_name, {:value => @position})%> | |
<%=h game_player.batting_avg %> | |
<%=h game_player.on_base_percentage %> | |
<%= link_to 'Destroy', game_player_path(params[:slug], game_player), :confirm => 'Are you sure?', :method => :delete %> | |
<% end %> | |
<% end %> | |
<%= submit_tag "Update Stats" %></td> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Update Multiple Game_players | |
def update_all | |
keys = params.keys.find_all{ |k| k =~ /game_player_\d+/ } | |
keys.each do |key| | |
id = key.split("_").last | |
@game_player = GamePlayer.find(id) | |
@game_id = @game_player.game_id | |
@game_player.update_attributes(params[key]) | |
end | |
@game = Game.find(@game_id.game_id) | |
format.html { redirect_to("/#{@team.slug}/games/#{@game.to_param}/edit_stats") } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment