举个例子:
def create
resource = build_resource
resource.assign_attributes(params[resource_instance_name], as: :admin)
create! do |format|
format.js {...}
end
end上面的问题是属性不是用as: :admin赋值的,它们是在没有任何检查的情况下赋值的,所以这个方法没有任何效果。是create!方法吗?属性正在别处分配给此资源,但我找不到它在哪里。感谢任何洞察力。
发布于 2012-11-09 13:20:13
我在这里找到了答案:https://github.com/josevalim/inherited_resources/pull/153。必须覆盖as_role和role_given? --
def as_role
{ as: current_user.highest_role }
end
def role_given?
true
end然后,这将始终将角色应用于定义它的控制器的属性,或者所有资源的属性,如果您像我一样从主资源控制器继承的话。
https://stackoverflow.com/questions/13302105
复制相似问题