I have a User and an Organization model with a many-to-many association, via a Membership model. Users (there are no roles) should only be able to create, read, and update Organizations to which they belong as members.
I've put the following in from CanCanCan's Ability class and have a load_and_authorize_resource
on the Organization model.
can [:create, :read, :update], Organization do |organization|
!(organization.memberships & user.memberships).empty?
end
When I load /organizations (index page), @organizations
is nil.
When I set @organizations = Article.accessible_by(current_ability)
I get the following error:
The accessible_by call cannot be used with a block 'can' definition. The SQL cannot be determined for :index Organization(id:integer...
The docs mention advice to use SQL, but I don't quite understand how.