Open phlegx opened 11 years ago
Can you construct a hash of conditions for where
to select the appropriate records? If so, use that instead.
If you cannot, you will need to pass an SQL fragment.
https://github.com/ryanb/cancan/wiki/Defining-Abilities-with-Blocks
@graywh thanks! Could you give me an example of how to use a hash of conditions for "where" with a non-block statement to select the appropriate records?
I'm trying to figure out how to construct that.
thank you!
@phlegx did you solve this issue? If so, can you share you solution? Thanks.
You can do it, but you will have to split it into two statements. Rails doesn't do OR
with hashed conditions, but cancan puts abilities together with OR
. The following should work:
def initialize(user)
user ||= User.new
can :manage,
Authentication,
:user_id => user.id
can :manage,
Authentication,
:organization_id => user.organization_id
end
Using active_admin together with cancan results in an error:
My block description does look like the following:
It seems that cancan doesn't like accessible_by calls when the cancan definition is written in a block. Any ideas what I can do about this? Is it possible to write the block above in a non-block fashion? If yes, how?
cu