gpt4 book ai didi

ruby - cancancan 创建权限不能正常使用条件散列

转载 作者:数据小太阳 更新时间:2023-10-29 08:11:33 24 4
gpt4 key购买 nike

我希望管理员用户能够为此帐户创建新用户并从该帐户读取、更新用户。

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com