Why is my Rails mountable engine not loading helper methods correctly?

淺唱寂寞╮ 提交于 2019-12-02 17:38:18

I think the Rails guides has the answer here.

To include that particular helper from your Engine in your app:

class ApplicationController < ActionController::Base
  helper MyEngine::ApplicationHelper
end

To include all helpers from your Engine in your app:

class ApplicationController < ActionController::Base
  helper MyEngine::Engine.helpers
end

To load the engine's GemName::ApplicationHelper to be used in the views of the engine itself, I added following to the engine.rb:

module GemName
  class Engine < ::Rails::Engine
    isolate_namespace GemName

    initializer 'local_helper.action_controller' do
      ActiveSupport.on_load :action_controller do
        helper GemName::ApplicationHelper
      end
    end
  end
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!