CanCan 自定义操作不适用于块
我正在更改能力类中的一些自定义 CanCan 操作,以使用块而不仅仅是哈希,但现在它们实际上已经停止限制访问。奇怪的是,像 :manage 和 :create 等内置操作似乎仍然可以与块一起正常工作。
这是一个例子:
旧的
# this one works
can :share, Project, :user_id => user.id
新
# this one doesn't work
can :share, Project do |project|
project.users.exists?(user)
end
以前有人遇到过这个问题吗?
I'm changing some of my custom CanCan actions in the Ability class to use blocks instead of just a hash but now they've stopped actually restricting access. The odd thing is that the built in actions like :manage and :create, etc. seem to still be working fine with the blocks.
This is one example:
OLD
# this one works
can :share, Project, :user_id => user.id
NEW
# this one doesn't work
can :share, Project do |project|
project.users.exists?(user)
end
Anyone run into this issue before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不能说太多关于你不想要的行为,但你可能不应该改变哈希来阻止,因为这些哈希使你能够获取记录。
请在 CanCan wiki 中仔细阅读本文。
I can't say much about your undesired behavior, but you probably shouldn't be changing hashes to block, as these hashes give you the ability of fetching records.
Read this article carefully in CanCan wiki.