2011-01-30 41 views
0

我的routes.rb:Ruby on Rails3:我如何在路由中包含非標準方法?

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 

回答

1
resources :boards do 
    match 'take_turn', :on => :collection 
end 

默認路徑:take_turn_boards_path

0

我認爲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)))'