Split routes into multiple files

suggest change

If your routes file is overwhelmingly big, you can put your routes in multiple files and include each of the files with Ruby’s require_relative method:

config/routes.rb:

YourAppName::Application.routes.draw do
  require_relative 'routes/admin_routes'
  require_relative 'routes/sidekiq_routes'
  require_relative 'routes/api_routes'
  require_relative 'routes/your_app_routes'
end

config/routes/api_routes.rb:

YourAppName::Application.routes.draw do
  namespace :api do
    # ...
  end
end

On Rails 5 and later, that constant is usually Rails.application. draw appends routes, so calling it again from the required file is what adds them.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents