A Simple Way to Decrease Complexity of Routes in Rails

Table of contents

Sometimes, when you are working with a large codebase, your routes.rb files grow really fast and become very dirty.

There are several things that make your routes file bigger:

  • Customization of devise;
  • Specific gems that mount additional routes (Active Admin, ActionCable);
  • Sidekiq + SidekiqWeb + Basic authentication;
  • Namespaces with APP or API.

All these points lead to one fact  - your file grows and it is getting hard to maintain it.

However, do you need all this staff in regular work, when you add some controller with another resource? My answer is No!

With that line of code we can split our routes.rb file into small compact pieces and forget about huge and long file.

After routes splitting

Solution is pretty simple and elegant. At the same time, it makes life easier, especially in rails development :)

Don't want to miss anything?

Subscribe and get stories like these right into your inbox.

Keep reading

How to Speed Up Your Tests via :build_stubbed

How to Speed Up Your Tests via :build_stubbed

Rspec is an awesome thing that was created for ruby community. Most of us write tests. However, sometimes in large projects our test becomes really slow. So, each launch of the test really hurts and it does not meter whether you launch your test before commit/push or on CI. When your test suits pass over 30 minutes  -  something definitely went wrong.

Contact us

Let's explore how our expertise can help you achieve your goals! Drop us a line, and we'll get back to you shortly.