Class: Ability
- Inherits:
-
Object
- Object
- Ability
- Includes:
- CanCan::Ability
- Defined in:
- app/models/ability.rb
Overview
Defines abilities
This class defines the abilities available to User Roles. Will be used by CanCan.
Class Method Summary collapse
-
.roles ⇒ Object
Available roles.
-
.roles_for_collection ⇒ Object
Prepare roles to show in select inputs etc.
Instance Method Summary collapse
-
#initialize(user) ⇒ Ability
constructor
Main role/ability definitions.
Constructor Details
#initialize(user) ⇒ Ability
Main role/ability definitions.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/ability.rb', line 20 def initialize(user) user ||= User.new # guest user alias_action :index, :to => :list alias_action :current, :to => :show if user.role? :admin can :manage, :all elsif user.role? :accountant can :manage, [Account, BookingTemplate, Customer, Employee, Invoice, Product, AccountType, Booking, Company, Day, Employment, Person, Profit] can [:show, :list], [Tenant], :users => {:id => user.id} can [:show, :update], User, :id => user.id end end |
Class Method Details
.roles ⇒ Object
Available roles
10 11 12 |
# File 'app/models/ability.rb', line 10 def self.roles ['admin', 'accountant'] end |
.roles_for_collection ⇒ Object
Prepare roles to show in select inputs etc.
15 16 17 |
# File 'app/models/ability.rb', line 15 def self.roles_for_collection self.roles.map{|role| [I18n.translate(role, :scope => 'cancan.roles'), role]} end |