在此模型中,预定的游戏和玩家是特许经营的嵌套资源,路由设置如下:
OTH::Application.routes.draw do
resources :franchises do
resources :scheduled_games
resources :players
end
我可以正确创建这些模型对象。但我必须在视图中做错事,看起来像这样:
<% @franchise.scheduled_games.each do |game| %>
<p class="games">
<span class="date">
<b>Opponent:</b> <%= game.opponent %>
<b>date:</b> <%= game.date %>
<%= link_to 'Edit',edit_franchise_scheduled_game_path(@franchise) %>
</span> </p>
<% end %>
显示此视图时,有两件事情出错。最糟糕的是每个编辑链接对于嵌套资源具有相同的id(/ franchises / 1 / scheduled_games / 1 / edit),即使该项的其他信息是正确的。
其次是始终显示空白记录。
我哪里出错了?
更新以下是佣金路线的输出:
franchise_scheduled_games
GET /franchises/:franchise_id/scheduled_games(.:format) {:action=>"index", :controller=>"scheduled_games"}
POST /franchises/:franchise_id/scheduled_games(.:format) {:action=>"create", :controller=>"scheduled_games"}
new_franchise_scheduled_game
GET /franchises/:franchise_id/scheduled_games/new(.:format) {:action=>"new", :controller=>"scheduled_games"}
edit_franchise_scheduled_game
GET /franchises/:franchise_id/scheduled_games/:id/edit(.:format) {:action=>"edit", :controller=>"scheduled_games"}
franchise_scheduled_game
GET /franchises/:franchise_id/scheduled_games/:id(.:format) {:action=>"show", :controller=>"scheduled_games"}
PUT /franchises/:franchise_id/scheduled_games/:id(.:format) {:action=>"update", :controller=>"scheduled_games"}
DELETE /franchises/:franchise_id/scheduled_games/:id(.:format) {:action=>"destroy", :controller=>"scheduled_games"}
franchise_players
GET /franchises/:franchise_id/players(.:format) {:action=>"index", :controller=>"players"}
POST /franchises/:franchise_id/players(.:format) {:action=>"create", :controller=>"players"}
new_franchise_player
GET /franchises/:franchise_id/players/new(.:format) {:action=>"new", :controller=>"players"}
edit_franchise_player
GET /franchises/:franchise_id/players/:id/edit(.:format) {:action=>"edit", :controller=>"players"}
franchise_player
GET /franchises/:franchise_id/players/:id(.:format) {:action=>"show", :controller=>"players"}
PUT /franchises/:franchise_id/players/:id(.:format) {:action=>"update", :controller=>"players"}
DELETE /franchises/:franchise_id/players/:id(.:format) {:action=>"destroy", :controller=>"players"}
答案 0 :(得分:1)
您需要在using link_to
with nested resources:
game
edit_franchise_scheduled_game_path(@franchise, game)
答案 1 :(得分:0)
因为他们使用REST模式,所以如果你想删除资源,你可以使用与GET请求相同的URL的HTTP / Delete请求。