我的routes.rb:
resources :board
root :to => 'application#index'
match ':controller(/:action(/:id(.:format)))'
在我的BoardController中我有一个名为take_turn
但是当我点击指向电路板#take_turn的链接时,我收到错误:
Unknown action
The action 'show' could not be found for BoardController
链接如下所示:
http://localhost:3000/board/take_turn?x=0&y=0
答案 0 :(得分:1)
resources :boards do
match 'take_turn', :on => :collection
end
默认路径:take_turn_boards_path
答案 1 :(得分:0)
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
之前放置:路由优先级问题
答案 2 :(得分:0)
我假设您的案例中的take_turn
是集合上的GET方法。
resources :board do
collection do
get :take_turn
end
# OR
get :take_turn, :on => :collection
end
p.s:超出主题..最佳做法是最好关闭通配符路由以防止意外行为:
#match ':controller(/:action(/:id(.:format)))'