Tôi đang cố tạo một tuyến đường mới để tôi có thể sử dụng tính năng biến đường dẫn của RoR tức là new_game_path. Trong trường hợp của tôi, tôi muốn sử dụng load_game_pathTuyến đường tùy chỉnh Ruby On Rails luôn chuyển hướng đến hành động hiển thị của bộ điều khiển
Tôi đã tạo ra một hành động cho bộ điều khiển thích hợp và hiện đang được định tuyến như sau:
resources :games do
get 'load', on: :collection
end
Mỗi lần tôi sử dụng load_games_path nó sử dụng URI đúng nhưng dường như chuyển hướng đến hành động hiển thị của GamesController và hiển thị chế độ xem hiển thị kế thừa của Trò chơi.
Tôi đã kiểm tra tuyến cào và tôi thấy con đường mới được tạo ra của tôi với những gì dường như là mong muốn path/trò chơi/tải (đường dẫn tập tin: /views/games/load.html.erb)
load_games GET /games/load(.:format) games#load/
đường Rake:
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'
tôi là một phần nạp là một hành động được xác định trước cho bộ điều khiển. Chỉ để chắc chắn rằng đây không phải là vấn đề, tôi đã thử một tên tùy ý cho hành động đó - mang lại kết quả tương tự.
Tôi cũng đã thử điều này không có thành công:
match 'games/load(.:format)', :controller => 'games', :action => 'load'
Nhật ký nói gì? Nó sẽ cho bạn biết hành động nào đang được gọi. – Substantial
Đây là đoạn trích nhật ký. Bạn có thể thấy nó đang cố gắng gọi hành động hiển thị. Không chắc chắn thông số HTML id => 'load' có nghĩa là gì. ' Đã bắt đầu GET "/ games/load" cho 127.0.0.1 lúc 2013-07-25 21:07:36 -0400 Đang xử lý bởi GamesController # hiển thị dưới dạng HTML Tham số: {"id" => "load"} Đã hoàn thành 500 lỗi máy chủ nội bộ trong 4ms ActionView :: MissingTemplate (Thiếu trò chơi/chương trình, ứng dụng/hiển thị với {: locale => [: en],: formats => [: html],: handlers => [: erb,: builder,: coffee]} Tìm kiếm trong: * "W:/Rails/testApp/blog/app/views" ): actionpack ' – Andrew
Bạn có thể dán kết quả 'rake' ở đây không? Chỉ những người có liên quan đến trò chơi và với thứ tự bị thuyết phục. Bởi vì tôi nghĩ rằng nếu nó là posible rằng bạn có một con đường "vô tình" bắt tuyến đường và thông qua để hiển thị hành động – PeterWong