2010-11-06 82 views
15

我有一个我已经映射为资源的故事控制器。我为stories_controller添加了2种新方法,'top'和'latest'。但是当我尝试去example.com/stories/top时,我得到一个'没有ID = top'的故事。如何更改路由以识别这些网址?Rails:将自定义操作添加到资源

回答

33

尝试在Rails的2.X:

map.resources :stories, :collection => { :top => :get , :latest => :get } 

在Rails 3.x中:

resources :stories do 
    collection do 
    get 'top' 
    get 'latest' 
    end 
end 
相关问题