LoginSignup
11
13

More than 1 year has passed since last update.

Rails: CanCanでアクションごとに権限を設定する方法

Last updated at Posted at 2015-10-05

次のように指定する。

app/models/ability.rb
def initialize(user)
  can :update, ExampleClass
  can :create, ExampleClass
end

CRUD ( Create / Read / Update / Delete ) の四種類で指定しよう。

厳密には「アクション名」ではないので、edit / new / index / show は存在しなから注意だ。
たとえば CanCan で update を許可すると、 Rails では update と edit アクションの二つが許可されるぞ。


対応は次の通り。( CanCanでの指定 => Rails でのアクション)

  • read => index + show
  • update => update + edit
  • create => new + create
  • delete => delete
  • manage => 上記のアクション全て

-「CanCan アクション 権限」でググってもヒットしなかったのでメモ。

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

メンター受付

11
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
13