[英]How to incorporate Rails Engine ApplicationController methods in a main app?
如何将Rails引擎ApplicationController(它的方法)合并到主应用程序中? 我需要访问这些引擎控制器方法,并且我想在主应用程序的ApplicationController中不使用“包含”的情况下进行操作。
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的方法上 ,但是我的理解是,助手仅是视图可用的,而我需要在控制器中访问它们。
我之前曾对名为dynamic_menu的rails宝石进行过此操作
基本上看起来像
require 'dynamic_menu'
module DynamicMenu
class Engine < Rails::Engine
initializer "dynamic_menu.menu_items" do |app|
ActionController::Base.send :include, DynamicMenu::MenuItems
end
end
end
所以我假设您想要的是
require 'myEngine'
class Engine < Rails::Engine
initializer "myengine.load_helpers" do |app|
ActionController::Base.send :include, MyEngine::Helpers
end
end
您想添加在lib中找到的正在使用的.rb文件的需求,然后只需将模块发送到ActionController :: Base
在github上查看我的gem,它本质上很简单,也许可以提供一些指导。 评论,我可以进一步解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.