我希望管理员用户能够为此帐户创建新用户并从该帐户读取、更新用户。
can [:create, :read, :update], User, id: account_users_ids
如果 account_users_ids 不是空数组则不起作用。 我需要拆分权限才能使其正常工作
can :create, User
can [:read, :update], User, id: account_users_ids
将条件定义为有什么问题
can [:create, :read, :update], User, id: account_user_ids
谢谢
最佳答案
这可能有点晚了,但在 Ruby 2.0+ 中,您的条件散列被解释为关键字参数,在这种情况下 CanCanCan 将忽略它。
添加括号应该可以让它按预期工作:
可以 [:create, :read, :update], User, { id: account_user_ids }
另见:
关键字参数:https://robots.thoughtbot.com/ruby-2-keyword-arguments
CanCan::Ability#can
:https://github.com/CanCanCommunity/cancancan/blob/develop/lib/cancan/ability.rb#L132-L134
关于ruby - cancancan 创建权限不能正常使用条件散列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35315914/