[英]How to reload helpers on rails mountable engine
In my rails mountable engine: 在我的可安装导轨的引擎中:
config.to_prepare do
# works fine, and reload automatically in development
ApplicationController.helper :application
# works fine, but doesn't reload. After restart server, it works.
ApplicationController.helper Rails.application.helpers
It looks like fine when arg is symbol or string. 当arg是符号或字符串时,看起来不错。 But it doesn't work when arg is a module like Rails.application.helpers
. 但是,当arg是类似Rails.application.helpers
的模块时, Rails.application.helpers
。
Or is there a good way to get all helpers like [:application, :users]
from Rails.application.helpers
. 或者有什么好方法可以从Rails.application.helpers
获得[:application, :users]
类的所有帮助Rails.application.helpers
。
Rails: 4.2.3 滑轨:4.2.3
You can configure autoload_paths of the engine. 您可以配置引擎的autoload_paths。
lib/my_engine/engine.rb lib / my_engine / engine.rb
module MyEngine
class Engine < ::Rails::Engine
...
config.autoload_paths += Dir[Engine.root.join('app', 'helpers')]
end
end
http://api.rubyonrails.org/classes/Rails/Engine.html http://api.rubyonrails.org/classes/Rails/Engine.html
对于使用Rails 6的人,您可能希望尝试使用传统的自动装带器而不是zeitwerk
config.autoloader = :classic
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.