到目前为止,我的 routes.rb 文件看起来像这样:
resources :games do
resources :planets do
member do
get 'index' as: :play_game
end
end
end
这会创建这些(当我检查 rake 路线时)
play_game_game_planet GET /games/:game_id/planets/:id/index(.:format) planets#index
game_planets GET /games/:game_id/planets(.:format) planets#index
POST /games/:game_id/planets(.:format) planets#create
new_game_planet GET /games/:game_id/planets/new(.:format) planets#new
edit_game_planet GET /games/:game_id/planets/:id/edit(.:format) planets#edit
game_planet GET /games/:game_id/planets/:id(.:format) planets#show
PATCH /games/:game_id/planets/:id(.:format) planets#update
PUT /games/:game_id/planets/:id(.:format) planets#update
DELETE /games/:game_id/planets/:id(.:format) planets#destroy
但我想要的路径是(类似于第二行)
play_game GET /games/:game_id/planets(.:format) planets#index