Rails 3.1: Better way to expose an engine's helper within the client app

后端 未结 5 1872
夕颜
夕颜 2020-12-08 10:22

I have found a few articles addressing the issue of helpers within an engine not being accessible to the consuming (parent) application. To make sure we are all on the same

5条回答
  •  一向
    一向 (楼主)
    2020-12-08 10:42

    You can create an initializer to accomplish this like so:

    module MyEngine
      class Engine < Rails::Engine
        initializer 'my_engine.action_controller' do |app|
          ActiveSupport.on_load :action_controller do
            helper MyEngine::ImportantHelper
          end
        end
      end
    end
    

提交回复
热议问题