某些型號的屬性能力,我有一個郵政模型與:published
屬性(布爾)和用戶模型與role
屬性(串)。有三種角色:ROLES = %w[admin publisher author]
慘慘:限制用戶對設置基於角色
我不想讓用戶的作用是作者應能設置,或編輯,在:published
場對早報模型。
我使用的康康舞(和RailsAdmin GEM)和我的簡化Ability.rb文件看起來像這樣:
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
if user.role? :admin
can :manage, :all
elsif user.role? :publisher
can :manage, Post
elsif user.role? :author
# I want to prevent these guys from setting the :published attribute
end
end
end
任何人有什麼祕訣做這樣的事情?
好的,謝謝你,我會關注CanCan v2.0。謝謝 – stephenmurdoch 2011-05-07 14:34:11
我知道這並不完美,但我認爲你仍然可以使用'can not << your attribute >>,:klass bee',因爲它們在等待2.0時仍然是ruby中的方法。 – 2012-12-22 06:51:06