私は自分の能力を次のように定義しようとしています:
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
if user.role == 'admin'
can :manage, :all
elsif user.role == 'member'
can :manage, [User,Post] , :id => user.id
cannot :index, User # list users page
else
can :read, :all
end
end
end
そしてload_and_authorize_resource
、私の上に含まれていPostsController
ます。
create
定義を理解していれば、ゲスト ユーザーはアクションにアクセスできないはずですが、アクセスできPostsController
ます。
この動作の説明はありますか?
編集
解決しました!
before_filter :authenticate_user!
認証にDeviseを使用しているため、追加するのを忘れていたことに気付きました。