我有一个新的、可安装的 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 对话吗?