I have a standard cancancan setup. The Article model has an attribute approved. Then standard setup:
# articles controller
load_and_authorize_resource only: [:index, :show]
def show
end
# ability.rb
# Solution 1
# can :show, Article, { approved: true }
# Solution 2
can [:show], [Article] do |article|
article.approved?
end
When I try either of the solutions, the results return as expected in the console or debugger (i.e. ability.can?(:show, @article) returns true if the article has been approved, and false otherwise).
The strange thing is, the show view is still accessible in the browser, when the false returned above clearly states that it shouldn't be accessible.
I can't work out why?