康康舞和枚举仅在“show”上行动
我在 Rails 3 应用程序中使用 cancan 和 mysql DB。
当我基于枚举列创建规则时,我总是仅针对“显示”操作获得 AccessDenied。知道为什么吗? 我使用 enumerated_attribute 强制模型中的枚举和数据库中的实际 ENUM 类型列。
例子: 我有一个帖子,其枚举字段隐私为 ['PUBLIC','PRIVATE','LOCAL']。当我使用此规则时,我总是遇到 AccessDenied:
can :read, Post, :privacy => “公开”
所有其他规则都完美运行。上述规则对于“索引”操作也很有效。
更新1:
我的能力.rb:
class Ability
include CanCan::Ability
def initialize(user)
can :read, Post, :privacy => 'PUBLIC'
end
end
I'm using cancan in my rails 3 application with mysql DB.
When i create a rule based on an enum column i always get AccessDenied only for "show" action. Any idea why?
I use enumerated_attribute to enforce enums in the models and an actual ENUM type column in the database.
Example:
I have a Post that has an enum field privacy with ['PUBLIC','PRIVATE','LOCAL']. I always get AccessDenied when i use this rule:
can :read, Post, :privacy => 'PUBLIC'
Every other rule works perfectly. The above rule also works great on "index" action.
UPDATE 1:
My ability.rb:
class Ability
include CanCan::Ability
def initialize(user)
can :read, Post, :privacy => 'PUBLIC'
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在这里得到了解答:https://github.com/ryanb/cancan/issues/479
The question was answered here: https://github.com/ryanb/cancan/issues/479