I have the following in ability.rb
can :index, Thread
can :show, Thread do |thread|
1 == 2
end
I hard coded show to result as false to test a fail. Shockingly, show never fails. Both Thread index and Thread show both return without resulting in a CanCan access denied. What’s going on with that? Suggestions? Thx
As can be seen here
:indexand:showare aliases of:read, that means they are synonyms.When you say
can :index, Threadthat means the user will be able to read anything.When you later define second rule
can :show, Thread {|t| 1 == 2}, the CanCan query for successive rules is disjunctive, that isresult = rule1 or rule2. To have the result computed via differenceresult = rule1 - rule2usecannotfor the 2nd rule: