Posted 6 days ago. Visible to the public. Linked content. Auto-destruct in 55 days

Updated: Rails routes: Extracting collection actions into their own controllers

In modern Rails versions we can define nested resources in a collection { ... } block to namespace them into an existing resource:

resources :projects, only: :show do collection do resource :report, only: :show, controller: 'projects/report' end end

This generates the following routes:

GET /projects/:id => ProjectsController#show GET /projects/report => Projects::ReportsController#show

Note how /projects/report does not take a :project_id.

Thanks Jakob for the hint.

Growing Rails Applications in Practice
Check out our new e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

Owner of this card:

Henning Koch
Last edit:
5 days ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more