わかりました、いくつかのこと:
1) CanCan は非常に使いやすく、マイナー インストールの価値があります。2 つのユーザー インスタンス メソッド is_admin? がある場合の app/models/ability.rb の例を次に示します。そして is_reviewer?
class Ability
include CanCan::Ability
def initialize(user)
if user && user.is_reviewer?
can :access, :rails_admin
can :dashboard
cannot :read, [Class1, Class2, Class3]
can :read, Class4
end
if user && user.is_admin?
can :access, :rails_admin
can :manage, :all
end
end
end
RailsAdmin の設定には次のものが含まれます。
RailsAdmin.config do |config|
config.authorize_with :cancan
...
end
依存関係としてインストールするには、Gemfile に cancan を追加する必要があることを忘れないでください。
2) 次に、おそらくもっと価値があるのは、認証メソッドでリダイレクト コードをスローしたくないということです。代わりに、次を ApplicationController に追加することをお勧めします。
rescue_from Acl9::AccessDenied do |exception|
respond_to do |format|
format.json do
render :json => { :success => false, :message => "You do not have access to do this action." }
end
format.html do
flash[:error] = 'You do not have access to view this page.'
redirect_to root_url
end
end
end
あるいは単に:
rescue_from Acl9::AccessDenied do |exception|
flash[:error] = 'You do not have access to view this page.'
redirect_to root_url
end