新しいマウント可能なrails3.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と通信できるように設定する方法を誰かに教えてもらえますか?