Tag: rails engines

如何从rails 3.1引擎调用父应用程序的帮助方法

我正在构建一个使用“act as”格式的rails引擎来建立与父应用程序的User模型的关系。 module Cornerstone module ActsAsCornerstoneUser extend ActiveSupport::Concern module ClassMethods def acts_as_cornerstone_user(options = {}) #= Associations has_many :cornerstone_discussions #= Options Cornerstone::Config.auth_with << options[:auth_with] if options[:auth_with] Cornerstone::Config.auth_with.flatten! end end module InstanceMethods end end ActiveRecord::Base.send :include, ActsAsCornerstoneUser end 我希望开发人员能够使用:auth_with选项指定帮助器方法名称。 这个想法是开发人员将在父应用程序中指定一个帮助器方法,该方法将返回该会话的登录用户。 我的问题是,一旦开发人员指定了auth_with选项,我该如何调用该父应用程序的方法? 有没有更好的方法来获取父应用程序的登录用户? 我希望它尽可能灵活,以便它不依赖于简单地调用current_user 。