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?
Asked
Active
Viewed 3,023 times
4
-
possible duplicate of [Cancan accessible\_by](http://stackoverflow.com/questions/5344247/cancan-accessible-by) – lulalala Oct 21 '14 at 09:22
2 Answers
2
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
1
There is a great railscast about CanCan (made by its creator):
http://railscasts.com/episodes/192-authorization-with-cancan

Patrick Connor
- 582
- 5
- 17