【发布时间】:2013-07-26 00:49:33
【问题描述】:
我正在尝试创建一条新路线,以便我可以利用 RoR 的路径变量功能,即 new_game_path。就我而言,我想使用 load_game_path
我已经为合适的控制器创建了一个动作,目前路由如下:
resources :games do
get 'load', on: :collection
end
每次我使用 load_games_path 时,它都会使用正确的 URI,但似乎会重定向到 GamesController 的显示操作并显示游戏的继承显示视图。
我检查了 rake 路线,我看到我新创建的路线似乎是所需的路径 /games/load(文件路径:/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'
我知道加载是控制器的预定义操作。为了确保这不是问题,我尝试了一个任意名称的操作 - 产生相同的结果。
我也试过了,但没有成功:
match 'games/load(.:format)', :controller => 'games', :action => 'load'
【问题讨论】:
-
日志说什么?它会告诉你正在调用哪个动作。
-
这里是日志的sn-p。您可以看到它正在尝试调用 show 操作。不确定 HTML id => 'load' 参数的含义。 ' 在 2013 年 7 月 25 日 21:07:36 -0400 开始 GET "/games/load" for 127.0.0.1 由 GamesController#show 作为 HTML 参数处理:{"id"=>"load"} 完成 500 内部服务器错误在 4ms ActionView::MissingTemplate (缺少模板游戏/节目,应用程序/节目与 {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee] }. 搜索:* "W:/Rails/testApp/blog/app/views" ): actionpack '
-
你能把
rake routes的结果粘贴到这里吗?只有那些与游戏相关且具有持久顺序的。因为我在想你是否有可能有另一条路径“无意”抓住了这条路线并传递给展示行动 -
当然。我现在在原始帖子中包含了 rake 路线
标签: ruby-on-rails ruby routing