Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is possible CanCan can :manage, :all except one or more method?

I'm doing:

can :manage, :all if user.role == 'admin'

can :approve, Anuncio do |anuncio|
  anuncio.try(:aprovado) == false
end

My second method does not work because the :manage :all override it. Theres a way to declare can manage all except approve? and inside approve i just do

can :approve, Anuncio do |anuncio|
  user.role == 'admin' && anuncio.try(:aprovado) == false
end

What's the better solution?

like image 457
Bruno Sapienza Avatar asked May 10 '13 17:05

Bruno Sapienza


1 Answers

Try do it another way round, look into cancan wiki. Try:

can :manage, :all if user.role == 'admin'

cannot :approve, Anuncio do |anuncio|
  anuncio.try(:aprovado)
end
like image 71
Lucas Avatar answered Nov 02 '22 11:11

Lucas