Rails 3 Routing Error with Nested Resources -
in rails application, there many games, , each game has it's own set of leaderboards. makes sense then, have leaderboards nested in game, can leaderboard through game. setup routes.rb file such (the important part):
resources :games resources :leaderboards end
so updated controller appropriate game game_id passed in, , grab leaderboard information that. however, issues comes view. in section (auto generated view scaffold):
<% @leaderboards.each |leaderboard| %> <tr> <td><%= leaderboard.name %></td> <td><%= leaderboard.scorecolumnname %></td> <td><%= leaderboard.game_id %></td> <td><%= link_to 'show', [@game, leaderboard] %></td> <td><%= link_to 'edit', edit_game_leaderboard_path(leaderboard) %></td> <td><%= link_to 'destroy', [@game, leaderboard], :confirm => 'are sure?', :method => :delete %></td> </tr> <% end %> </table>
the code breaks saying:
no route matches {:action=>"edit", :controller=>"leaderboards", :game_id=>#<leaderboard id: 1, name: "test high score leaderboard", scorecolumnname: "score", game_id: 1, created_at: "2011-07-03 01:32:33", updated_at: "2011-07-03 01:32:33">}
this line, turns out error: (line 19 in code)
<td><%= link_to 'edit', edit_game_leaderboard_path(leaderboard) %></td>
removing line, , view renders fine. so, url part broken, how fix it? weird thing is, have exact "edit_game_leaderboard_path" in show view, , works fine... doing wrong?
you want:
<%= link_to 'edit', edit_game_leaderboard_path(@game, leaderboard) %>
Comments
Post a Comment