Rails 3.1: Better way to expose an engine's helper within the client app
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 endend
I have written two blog posts about creating engines from scratch, and following them everything should work as expected (without additional configurations needed). Maybe you are still interested in:
- Rails 3.1 Engines: Part I – The engine
- Rails 3.1 Engines: Part II – The gem
- Rails 3.1 Engines: Part III – The environment
Update: It's three articles in the meantime, and there's still some info to come. Please give me feedback.
If you want to keep the code in the engine, instead of every implementing application, use this:
module MyEngine class Engine < Rails::Engine isolate_namespace MyEngine config.to_prepare do MyEngine::ApplicationController.helper Rails.application.helpers end endend