method

collection

rails latest stable - Class: ActionDispatch::Routing::Mapper::Mapping::Resources

Method not available on this version

This method is only available on newer versions. The first available version (v8.1.1) is shown here.

collection(&block)
public

To add a route to the collection:

resources :photos do
  collection do
    get 'search'
  end
end

This will enable Rails to recognize paths such as `/photos/search` with GET, and route to the search action of `PhotosController`. It will also create the `search_photos_url` and `search_photos_path` route helpers.