[英]Ruby on Rails3: how do I include non-standard methods in the routes?
我的routes.rb:
resources :board
root :to => 'application#index'
match ':controller(/:action(/:id(.:format)))'
在我的BoardController中,我有一個名為take_turn
的方法
但是,當我單擊指向board#take_turn的鏈接時,出現錯誤:
Unknown action
The action 'show' could not be found for BoardController
鏈接看起來像這樣:
http://localhost:3000/board/take_turn?x=0&y=0
resources :boards do
match 'take_turn', :on => :collection
end
默認路徑:take_turn_boards_path
match 'board/take_turn/:x/:y' => "board#take_turn", :as => 'take_turn'
可以作為take_turn_path
訪問
http://guides.rubyonrails.org/routing.html#naming-routes
如果放在resources :board
之前resources :board
:路由優先級問題
我假設您的情況下的take_turn
是集合上的GET方法。
resources :board do
collection do
get :take_turn
end
# OR
get :take_turn, :on => :collection
end
ps:超出主題范圍。.最佳做法是最好關閉通配符路由以防止意外行為:
#match ':controller(/:action(/:id(.:format)))'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.