Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - CanCan - accessible_by

Can anyone explain to me how CanCan's accessible_by works? How does it know what the relationship is between the user and the thing that needs restricting?

like image 245
Mr Mikkél Avatar asked Nov 15 '25 15:11

Mr Mikkél


2 Answers

It checks the current user against a set of rules described in the abilities initializer which includes CanCan::Ability. When you call accessible_by it checks the rules specifed in the Ability class, and returns the records that the user has access to.
The gem's wiki is very good... here: defining abilities

like image 56
nodrog Avatar answered Nov 18 '25 04:11

nodrog


There is a great railscast about CanCan (made by its creator):

http://railscasts.com/episodes/192-authorization-with-cancan

like image 43
Patrick Connor Avatar answered Nov 18 '25 05:11

Patrick Connor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!