I am having trouble with defining a CanCan ability over a HABTM relationship such that it will work with the accessible_by method when I am NOT in the controller of the object
My model is as follows:
Test <--HABTM--> Organisation <--belongs_to-- User
So I am trying to restrict :read access to Job objects as follows:
can :read, ImplicitTest, :organisations => { :id => user.organisation_id }
This works for the Test index page – only the correct tests appear. But when I try and pull down this list on a view within another controller by invoking Test.accessible_by(current_ability, current_user) it seems to produce some odd SQL:
SELECT "tests".* FROM "tests" WHERE ('t'='f')
Is there any way to make this call work outside of the TestsController ?
Should have been calling
Test.accessible_by(current_ability, :index)– a lot of debugging got me the answer eventually.