简体   繁体   中英

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. But it doesn't work when arg is a module like Rails.application.helpers .

Or is there a good way to get all helpers like [:application, :users] from Rails.application.helpers .

Rails: 4.2.3

You can configure autoload_paths of the engine.

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

对于使用Rails 6的人,您可能希望尝试使用传统的自动装带器而不是zeitwerk

config.autoloader = :classic

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM