![](/img/trans.png)
[英]ruby on rails No route matches {:action=>“show”, :controller=>“pythonhowto”}
[英]Ruby On Rails custom route always redirects to controller's show action
我正在嘗試創建一個新路由,以便我可以利用RoR的路徑變量功能,即new_game_path 。 就我而言,我想使用load_game_path
我已經為適當的控制器創建了一個動作,並且當前路由如下:
resources :games do
get 'load', on: :collection
end
每次我使用load_games_path它都使用正確的URI,但似乎重定向到GamesController的show動作並顯示Games的繼承show視圖。
我檢查了rake路由 ,我看到了我新創建的路徑,看起來似乎是所需的路徑/游戲/加載(文件路徑:/views/games/load.html.erb)
load_games GET /games/load(.:format) games#load/
耙路:
welcome_index GET /welcome/index(.:format) welcome#index
players GET /players(.:format) players#index
POST /players(.:format) players#create
new_player GET /players/new(.:format) players#new
edit_player GET /players/:id/edit(.:format) players#edit
player GET /players/:id(.:format) players#show
PUT /players/:id(.:format) players#update
DELETE /players/:id(.:format) players#destroy
games GET /games(.:format) games#index
POST /games(.:format) games#create
new_game GET /games/new(.:format) games#new
edit_game GET /games/:id/edit(.:format) games#edit
game GET /games/:id(.:format) games#show
PUT /games/:id(.:format) games#update
DELETE /games/:id(.:format) games#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
/players/:name(.:format) players#index
load_games GET /games/load(.:format) games#load
GET /games(.:format) games#index
POST /games(.:format) games#create
GET /games/new(.:format) games#new
GET /games/:id/edit(.:format) games#edit
GET /games/:id(.:format) games#show
PUT /games/:id(.:format) games#update
DELETE /games/:id(.:format) games#destroy
root / welcome#index
routes.rb中:
get "welcome/index"
resources :players, :games, :users
match '/players/:name' => 'players#index'
# match 'games/load(.:format)', :controller => 'games', :action => 'load'
resources :games do
collection do
get 'load'
end
end
root :to => 'welcome#index'
我知道load是控制器的預定義動作。 為了確保這不是一個問題,我嘗試了一個任意名稱的行動 - 產生相同的結果。
我也試過這個沒有成功:
match 'games/load(.:format)', :controller => 'games', :action => 'load'
嘗試
resources :games do
collection do
get 'load'
end
end
現在,它將'games / load'解釋為'games /:id',其中:id參數設置為'load',並將'games /:id'路由到GamesController #show。
編輯:並確保沒有另一個resources :games
調用resources :games
路徑文件中較早的resources :games
,即使:游戲只是resources :players, :games
一個參數resources :players, :games
,因為您將無法在以后插入收集方法如果有。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.