【发布时间】:2011-09-19 06:33:32
【问题描述】:
我有一个新的、可安装的 rails 3.1 引擎,我需要客户端应用程序,即包含此引擎的 rails 应用程序,以定义一个基于权限的通用方法。
所以,我想要在我的引擎的博客控制器中说如下内容:
before_filter :redirect_unless_admin
然后我想将它留给客户端应用程序来定义谁是管理员。但是,每当我尝试这个时,我都会得到:
NameError in Blog::BlogsController#show
undefined local variable or method `redirect_unless_admin' for #<Blog::BlogsController:0x000001058aa038>
我的客户端应用控制器如下所示:
class ApplicationController < ActionController::Base
# Required by blog engine
def redirect_unless_admin
if !logged_in?
set_session_redirect
redirect_to login_path, :notice => 'Please log in.'
elsif !current_user.admin?
set_session_redirect
redirect_to root_path, :notice => 'You do not have permission to view this page.'
end
end
在我的引擎应用控制器中,我有以下内容:
module Blog
class ApplicationController < ActionController::Base
end
end
谁能告诉我如何设置它,以便我的引擎的博客控制器可以与我的客户的 application_controller 通信?
【问题讨论】:
-
我觉得this question的回答和你的情况有关。
-
德米特里,那篇文章与我所需要的相反。该票询问“我如何使引擎中的方法可用于应用程序”。我需要知道的是“如何使应用程序中的方法对引擎可用?”。此外,这是一个 3.1 引擎和应用程序,所以我的假设是为我们处理任何类型的帮助程序、视图、资产等加载(这就是为什么这让我如此困惑)。
标签: ruby-on-rails ruby-on-rails-3.1 rails-engines