Q:

Rails: Add Custom action to resource

I have a stories controller that i have mapped as a resource. I've added 2 new methods to stories_controller, 'top' and 'latest'. but when i try to go to example.com/stories/top I get a 'no story with ID=top' error. How can I change the routing to recognize these urls?

A:

Try in Rails 2.x:
map.resources :stories, :collection => { :top => :get , :latest => :get } 

In Rails 3.x:
resources :stories do 
  collection do 
    get 'top'
    get 'latest'
  end 
end 

