📎 Webclip
Split route namespaces into different files
The page argues that when a Rails app has a default route set plus several namespaces, keeping everything in one routes file makes the configuration harder to manage and easier to edit in the wrong namespace. It proposes moving each namespace into its own file.
Reading notes#
- The example starts with one
config/routes.rbcontaining the default routes and thedeveloper,admin, andapinamespaces together. - The text says this becomes difficult to maintain because the routes are similar across namespaces and easy to change in the wrong place.
- The suggested approach is to split the namespace routes into separate files such as
config/routes/developer.rb,config/routes/admin.rb, andconfig/routes/api.rb. - For Rails 2, the page shows an initializer that adds those route files with
ActionController::Routing::Routes.add_configuration_file. - For Rails 3, it shows adding all files from
config/routes/*.rbinconfig/application.rb. - The page says this setup makes it easier to change only the routes for one namespace and can reduce reloading work when only one route file changes.
