🖥

Rails: How to set permissions for each action in CanCan

2019/04/16に公開

Specify as follows.

 def initialize(user) can :update, ExampleClass can :create, ExampleClass end 

Let's specify four types of CRUD (Create / Read / Update / Delete).

Note that edit / new / index / show does not exist because it is not strictly an "action name". For example, if you allow update with CanCan, Rails will allow two actions, update and edit.


Correspondence is as follows. (Specified in CanCan => action in Rails)

  • read => index + show
  • update => update + edit
  • create => new + create
  • delete => delete
  • manage => all the above actions

-A note because it did not hit even if it is gugging with "CanCan action authority". -An easy way to separate administrators and general users with Cancan-Based on the setting of roles (authorization) for each user type .

Original by

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

About

About this translattion

チャットメンバー募集

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

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-04-16

Discussion