Search code examples
ruby-on-railsrestroutesnested-resources

How to add additional rest routes to a nested resource in rails


I have a widget that has many links. In the routes file:

map.resources :widgets, :has_many => [:links]

I want to add a "sort" action to links. What do I need to add to the routes file, so I can write sort_widget_links_path(widget)


Solution

  • You can define it using a block:

    map.resources :widgets do |widget|
      widget.resources :links, :member => {:sort => :get}
    end