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

1

11

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?

Incommode answered 10/5, 2013 at 17:8 Comment(1)
Ruby en los Carriles :')Lanark
B
22

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
Bilge answered 10/5, 2013 at 17:45 Comment(2)
I should pay more attention into the wiki, thanks a lot for answer! =)Incommode
unfortunately i can't vote up because as i'm new here in stackoverflow, i haven't enough reputation to do it :/ i need 15 reputation points! lol =)Incommode

© 2022 - 2024 — McMap. All rights reserved.