abloom (owner)

Fork Of

Revisions

  • b5041e abloom Tue May 12 07:20:20 -0700 2009
  • 79ed5b Tue May 12 05:49:09 -0700 2009
  • 3e29b7 Tue May 12 05:45:29 -0700 2009
  • 17226d Tue May 12 05:44:59 -0700 2009
gist: 110508 Download_button fork
public
Public Clone URL: git://gist.github.com/110508.git
fha/games/7/edit_stats.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#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 %>
game_players controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
#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