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

后端 未结 3 1819
轻奢々
轻奢々 2021-02-08 04:50

How to force rails 4 to reload all route files?
That is without having to restart the application to make the routes from /config/routes/.rb get loaded*

3条回答
  •  生来不讨喜
    2021-02-08 05:35

    In Rails 3, if you are splitting the routes.rb file into multiple files, we have to add this line to application.rb:

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

    ...and the corresponding routes in config/routes/*.rb files like this:

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

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

    Just add the corresponding routes under config/routes/*.rb.

提交回复
热议问题