一种从引擎向应用程序添加before_filter的方法 [英] A way to add before_filter from engine to application

查看:66
本文介绍了一种从引擎向应用程序添加before_filter的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然没有很多特定的代码,但这只是模糊的,但是我会尽力提供.

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

考虑到Rails引擎,基本引擎而不是其自身空间中的可安装引擎,我如何将引擎中的方法作为应用程序控制器的before_filter提供给应用程序?

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?

我一直在浏览Devise代码,因为我想要的东西与我在Devise方面的经验相似,但是我承认我对很多事情不了解.

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.

如果将include Myengine::Mymodule放入要使方法可供过滤的apps控制器中,则可以执行此操作,但是我希望可以仅使用这些方法而不必包含模块.

I can do this if I put include Myengine::Mymodule in the apps controllers where I want to have the methods available for filtering, but I want it possible to just use the methods without having to include the modules.

这是尝试将Rails应用程序转换为要由多个Rails应用程序使用的引擎的最新障碍,对于获得适当的命名空间,模块配置等方面的指导,我们将不胜感激.

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

这篇关于一种从引擎向应用程序添加before_filter的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆