Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You may also want to look into the initializers inside your engine subclass, so you don't have to include view helpers inside your controller class. And this will give you control over the load order of these modules.</p> <p>Here is what I have been using:</p> <pre> <code> module MyEngine class Engine &lt; Rails::Engine initializer 'my_engine.helper' do |app| ActionView::Base.send :include, MyEngineHelper end initializer 'my_engine.controller' do |app| ActiveSupport.on_load(:action_controller) do include MyEngineActionControllerExtension end end end end </code> </pre> <p>Also, another option for the action controller extension is using a mixin module. This will let you use the before_filter, after_filter, etc..</p> <pre> <code> module MyEngineActionControllerExtension def self.included(base) base.send(:include, InstanceMethods) base.before_filter :my_method_1 base.after_filter :my_method_2 end module InstanceMethods #........... end end </code> </pre> <p>One other thing... if you create the default rails directories at the top level of your gem, you don't have to worry about requiring the helpers or controllers. Your engine subclass has access to them. So I add my application controller and application helper extensions here:</p> <pre> /myengine/app/helpers/myengine_application_helper_extension.rb /myengine/app/controllers/my_engine_action_controller_extension.rb </pre> <p>I like this setup because it looks similar to the application_controller and application_helper in your rails app. Again, this is just personal preference, but I try to keep anything that is directly rails related, such as controllers, helpers and models inside /my_engine/app and anything that is related to the plugin in general inside /my_engine/lib</p> <p>Check out this tutorial by Jose Valim for more info on initializers: <a href="https://gist.github.com/e139fa787aa882c0aa9c" rel="noreferrer">https://gist.github.com/e139fa787aa882c0aa9c</a> (engine_name is deprecated now, but most of this doc seems up-to-date)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload