Read more

Clean your Rails routes: grouping

Florian Leinsinger
August 27, 2020Software engineer at makandra GmbH

In Ruby on Rails, all the routes of a given application can be found within the config/routes.rb file.
You add more and more routes in this file as your project grows.

The problem here is that this file potentially becomes very complicated to manage over the time.
That’s why it’s important to find a way to order and maintain your routes.

See: Clean your Rails routes: grouping Show archive.org snapshot

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

Sometimes the routes.rb grows very fast and each line adds more confusion to it. Maybe it is time for a new approach.

The quoted article suggests to split up your routes.rb into small partials to keep it clean. For example you can create a own file for each namespace and separately.

config/routes
  ├── backend.rb
  └── frontend.rb

Then you have to configure the paths in your config/application.rb:

config.paths['config/routes.rb'] = Dir[Rails.root.join('config/routes/*.rb')]
Posted by Florian Leinsinger to makandra dev (2020-08-27 21:26)