Rails 4.2:如何强行重新加载(引擎的)路由?

时间:2016-03-23 04:22:42

标签: ruby-on-rails ruby-on-rails-4

如何绝对强制重新加载before_action中的路线?仅当Rails.application.reload_routes!发生更改时,routes.rb才会重新加载路由。

以下是ActionDispatch::Routing中关于如何重新加载路线的章节:

Reloading routes

You can reload routes if you feel you must:

Rails.application.reload_routes!

This will clear all named routes and reload routes.rb if the file has been modified from last load. To absolutely force reloading, use reload!.

除了提及reload!之外,没有关于如何强制重新加载的详细信息。在Rails.application.reload!中尝试before_action但它无效。在application controller

before_action :reload_route

def reload_route
  Rails.application.reload_routes!
end

如果引擎名称为MyEngine,那么强行重新加载路线的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

config.paths["config/routes.rb"] << YOUR_ROUTE_FILE