Class: Ability

Inherits:
Object
  • Object
show all
Includes:
CanCan::Ability
Defined in:
app/models/ability.rb

Instance Method Summary (collapse)

Constructor Details

- (Ability) initialize(user)

This method sets up the user's abilities to view pages

look at https://github.com/ryanb/cancan for more info


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/models/ability.rb', line 6

def initialize(user)
  user ||= User.new # guest user

  if user.super_admin?
    can :manage, :all
  elsif user.admin?
    can :manage, :all
  else
    can :read, Order, :user_id => user.id
    can :manage, Order do |action, order|
      action != :destroy && order.state != 'complete' && order.user_id == user.id
    end

  end
end