A word of caution
There should rarely be a reason for you to split up config/routes.rb
. If you need to, probably your whole application should be split up.
Split it anyway
Rails::Engine
looks at config.paths['config/routes.rb']
and registers its value with app.routes_reloader
. This means you could put routing files anywhere and then require them. However, I recommend to put any routing files into config/routes/
:
# config/routes/example.rb
Rails.application.routes.draw do
resources :example
end
After creating your routing files, tell Rails how to find them:
# in config/application.rb
# Rails::Engine will register these files with app.routes_reloader
config.paths['config/routes.rb'] = Dir[Rails.root.join('config/routes/*.rb')]
Note that this will neglect your old config/routes.rb
(which by now should be empty, anyway). However, you might want to leave a note to other developers:
# config/routes.rb
# See config/routes/*.rb
Posted by Dominik Schöler to makandra dev (2015-08-13 13:53)