Class: AbilityDecorator

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

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ AbilityDecorator

Returns a new instance of AbilityDecorator.



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

def initialize(user)
  can :index, Page
  can :read, Page do |page|
    page.published_at || user.has_role?(:admin) || (page.user == user)
  end
  can :update, Page do |page|
    user.has_role?(:admin) || (page.user == user)
  end
  can :index, Post
  can :read, Post do |post|
    post.published_at || user.has_role?(:admin) || (post.user == user)
  end
  can :update, Post do |post|
    user.has_role?(:admin) || (post.user == user)
  end
end