开发者

A way to add before_filter from engine to application

Without a lot of specific code, this is just vague, but I'll provide what I can.

Given a rails engine, a basic engine and not a mountable engine in its own space, how do I make methods from the engine available to the application as a before_filter for the applications controllers?

I've been looking through the Devise code, because what I want to is similar from my experience with Devise, but I'll admit I don't understand a lot of what I'm going over.

I can do this if I put include Myengine::Mymodule in the apps controllers where I want to have the met开发者_如何学Pythonhods available for filtering, but I want it possible to just use the methods without having to include the modules.

This is the latest roadblock in trying to turn a rails application into an engine to be used by multiple rails apps, and any guidance on getting a handle on proper namespacing, module config, etc., is appreciated.


If I understood you correctly you can use initializer, for example:

module MyEngine
    class Engine < Rails::Engine
        initializer  "myengine.load_helpers" do
            ActiveSupport.on_load(:action_controller) do
                include MyEngine::Helpers
            end
        end
    end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜