1
  1. How can I use CanCan from a Model?

  2. Let's say I have a relationship like this: Employee belongs_to Store, and Boss manages_many (has_many) Stores. How exactly do I use CanCan (the right way) to restrict each particular boss's access to be able to only read or update etc employees that belong to his particular store?

Many thanks to whomever can answer! :)

Mr Mikkél
  • 2,577
  • 4
  • 34
  • 52

2 Answers2

0

You should not use CanCan in a model. The model doesn't know about who is making a request, and the entire point of CanCan is to handle authorization of requests (which happens in the controller layer).

Please tell me what it is that you are wanting to do with CanCan in your Model, and I'll do my best to help you find a way to do this through the controller (and the rationale for why you should do it this way).

Andrew
  • 42,517
  • 51
  • 181
  • 281
0

You might want to try this plugin: Fat Model Auth

All rules for a model are defined on the model itself.

Brent Greeff
  • 174
  • 1
  • 6