繁体   English   中英

声明式授权和if_attribute不起作用

[英]Declarative authorization and the if_attribute not working

我遇到的问题几乎和维克多·马丁Victor Martin)一样 (您可以在此处看到所提出的问题)。

我有声明式授权,可用于几乎不涉及使用条件句的所有内容。 例如

has_permission_on :users, :to => [:edit, :update, :destroy] do
if_attribute :user => is { current_user }
end

声明性授权有什么共同的陷阱吗? 我使用的是authlogic,我怀疑应用程序控制器中的“ current_user”方法可能是问题的根源。

请注意,如果您在控制器中使用“ filter_access_to”,则需要确保您具有“:attribute_check => true”。 没有它,条件“ if_attribute”声明将不起作用。

声明式授权文档中有关此内容的更多详细信息

您还需要将其添加到ApplicationController中:

before_filter :set_current_user
protected
def set_current_user
  Authorization.current_user = current_user
end

然后您的规则将如下所示:

has_permission_on :users, :to => [:edit, :update, :destroy] do
  if_attribute :user => is { user }
end

据我所知,declarative_authorization不会在crontroller上调用任何方法,也不知道current_user在您的示例中的含义,但它为您提供了一个Authorization.current_user实例,称为user ,您可以在authorization_rules.rb文件中使用该user

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM