class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
if user.persisted?
if user.admin?
can :manage, :all
elsif user.moderator?
can :manage, Post, Comment
elsif user.client?
can :create, Post
can [:update, :destroy], Comment, user_id: user.id
end
end
can :read, :all
end
end