How to reload routes / config / routes / * in rails 4?

How to make rails 4 reload all route files?
It does not need to restart the application to load routes from /config/routes/.rb * I split them in /config/routes/.rb but these / config / routes / files are not reloaded.

This worked on rails 3 but not 4:

#config.paths['config/routes'].unshift *Dir["config/routes/*.rb"] 
+7
reload ruby-on-rails-4 routes
source share
3 answers

You can use:

 Rails.application.reload_routes! 

You can read about it here (you will need to use find )

+9
source share
 config.paths["config/routes.rb"] << YOUR_ROUTE_FILE 
+4
source share

In Rails 3, if you split the routes.rb into multiple files, we must add this line to application.rb:

 config.paths['config/routes'].concat Dir[Rails.root.join("config/routes/*.rb")] 

... and the corresponding routes in the config/routes/*.rb files, for example:

 TestApp::Application.routes.draw do namespace :api do resources :test end end 

In Rails 4, Rails no longer provides the key ["config/routes"] in Rails::Engine.paths . However, in Rails 4 there is no need to add to config.path in application.rb .

Just add the appropriate routes to <<22>.

0
source share

All Articles