単一のユーザー分類にbefore_filterを使用する方法が十分に文書化されていることを考えると、複数のユーザータイプのアクションレベルの保護を取得するのに問題があります。説明させてください:
私はこのようなものを持っています...
class ApplicationController < ActionController::Base
class << self
attr_accessor :standard_actions
end
@standard_actions = [:index, :show, :new, :edit, :create, :update, :destroy]
def require_guardian
unless current_user and current_user.is_a?(Guardian)
store_location
redirect_to home_url
return false
end
end
def require_admin
unless current_user and current_user.is_a?(Administrator)
store_location
redirect_to register_url
return false
end
end
end
また、GuardiansControllerでは、Administratorの標準アクションのみを許可したいのですが、他のすべてのアクションにはGuardianが必要です。だから私はこれを試しました...
class GuardiansController < ApplicationController
before_filter :require_admin, :only => ApplicationController::standard_actions
before_filter :require_guardian, :except => ApplicationController::standard_actions
...
end
これは、再帰的なリダイレクトを実行することになります。より良い方法があるに違いありませんか?