4

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?

hcarver
  • 7,126
  • 4
  • 41
  • 67
Mr Mikkél
  • 2,577
  • 4
  • 34
  • 52
  • possible duplicate of [Cancan accessible\_by](http://stackoverflow.com/questions/5344247/cancan-accessible-by) – lulalala Oct 21 '14 at 09:22

2 Answers2

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

JJD
  • 50,076
  • 60
  • 203
  • 339
nodrog
  • 3,532
  • 2
  • 25
  • 31
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