3

I want admin User to be able to create new users for this account and read, update users from this account.

can [:create, :read, :update], User, id: account_users_ids

is not working if account_users_ids is not en empty array. I need to split permissions to get it working

can :create, User
can [:read, :update], User, id: account_users_ids

what is wrong with defining conditions as

can [:create, :read, :update], User, id: account_user_ids

thanks

user1136228
  • 967
  • 9
  • 22

1 Answers1

0

This may be a little late, but in Ruby 2.0+ your hash of conditions is interpreted as a keyword argument, which CanCanCan ignores in this instance.

Adding brackets should allow this to work as expected:

can [:create, :read, :update], User, { id: account_user_ids }

See also:

Keyword Args: https://robots.thoughtbot.com/ruby-2-keyword-arguments

CanCan::Ability#can: https://github.com/CanCanCommunity/cancancan/blob/develop/lib/cancan/ability.rb#L132-L134

cyber_dave
  • 2,019
  • 1
  • 16
  • 21