When using Cancan/can, a
Ability class in a larger Ruby on Rails application can grow quite quickly.
This gem lets you seperate model specific ability definitions into their own class.
This is a first approach to solve this. Pull Requests to make things easier to use are very much appreciated.
Add the following lines to your
gem 'cancancan' gem 'classy_cancan'
And this is how you use it:
# app/models/ability.rb class Ability include CanCan::Ability def initialize(user) ContactAbility.setup(self, user) end end # app/models/abilities/contact_ability.rb class ContactAbility < ClassyCancan::BaseAbility def setup can :manage, Contact end end
- Rails generator to create ability classes
This project rocks and uses MIT-LICENSE.