Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 绕过Rails控制台中的Cancan角色验证_Ruby On Rails_Ruby_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 绕过Rails控制台中的Cancan角色验证

Ruby on rails 绕过Rails控制台中的Cancan角色验证,ruby-on-rails,ruby,ruby-on-rails-3,Ruby On Rails,Ruby,Ruby On Rails 3,我已经创建了一个帮助程序,它检查当前用户的角色,以防止未经授权的用户编辑某些属性 除了在控制台中,验证工作正常。显然没有用户,但它仍在尝试验证,我得到: NoMethodError: undefined method `has_role?' for nil:NilClass 我如何绕过这个验证,或者有更好的方法来实现我正在做的事情 位置模型: validate :check_archived_status, :on => :update def check_archived_

我已经创建了一个帮助程序,它检查当前用户的角色,以防止未经授权的用户编辑某些属性

除了在控制台中,验证工作正常。显然没有用户,但它仍在尝试验证,我得到:

 NoMethodError: undefined method `has_role?' for nil:NilClass
我如何绕过这个验证,或者有更好的方法来实现我正在做的事情

位置模型:

  validate :check_archived_status, :on => :update

  def check_archived_status
    unless UserHelper.staff
      if self.archived == false
        if stuff == otherstuff
          do some other stuff
        end
      end
    end    
  end
用户助手:

def self.staff
  staff = User.current_user.has_role?('Super', 'Admin', 'Tech')
end

您不能在控制台上用一些随机用户填充当前用户吗?

如下所示:
current\u user=user.last
,因此验证不会给您任何错误。

您不能在控制台上用一些随机用户填充
current\u user
current_user=user.last
,因此验证不会给您任何错误。我已经为解决方案苦苦挣扎了好几天,这是世界上最简单的解决方案!你能给我一个答案让我接受吗??