Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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 设计“先发现后验证条件”的解释_Ruby On Rails_Ruby_Activerecord_Devise - Fatal编程技术网

Ruby on rails 设计“先发现后验证条件”的解释

Ruby on rails 设计“先发现后验证条件”的解释,ruby-on-rails,ruby,activerecord,devise,Ruby On Rails,Ruby,Activerecord,Devise,尽管我已经阅读了文档并做了一些研究,但我还是很难从中理解这段代码 def self.find_first_by_auth_conditions(warden_conditions) conditions = warden_conditions.dup signin = conditions.delete(:signin) where(conditions).where(["lower(username) = :value OR lower(email) = :value",

尽管我已经阅读了文档并做了一些研究,但我还是很难从中理解这段代码

def self.find_first_by_auth_conditions(warden_conditions)
  conditions = warden_conditions.dup
  signin = conditions.delete(:signin)
  where(conditions).where(["lower(username) = :value OR lower(email) =
    :value", {:value => signin.downcase }]).first
end
请解释上述方法这一部分的组成部分:

where(conditions).where(["lower(username) = :value OR lower(email) =
  :value", {:value => signin.downcase }]).first
正则表达式通过:

上述代码考虑将
电子邮件
用户名
列的所有以前记录存储为小写,如下所示:

before_save :downcase_fields

def downcase_fields
  self.email.downcase
  self.username.downcase
end

根据典狱长条件运行的查询的第一个结果加上用户名或电子邮件等于登录值。有什么问题吗?@DaveNewton:谢谢,你能用一种更简单的形式来解释一下吗。我不能从整体上理解它。
典狱长条件。dup
-复制典狱长条件。然后
条件。删除(:signin)
删除登录值。然后找到具有这些条件的第一条记录,用户名或电子邮件是登录值,如Dave所说,可能您对
条件感到困惑。delete(:signin)
返回删除的值?有人可以为相同的值编写等效的查询吗。where(conditions).where([“lower(username)=:value或lower(email)=:value”,{:value=>sign.downcase}])。首先感谢您提供了完整的代码,但再次感谢您的代码与此相关。。where(条件)。where([“lower(username)=:value或lower(email)=:value”,{:value=>sign.downcase}])。首先,你可以为它编写等价的查询。@Java基本上它不是等价的,但为了说明的目的,它足够接近了。希望能有帮助
lower(username)
查询列时,就好像它都是小写的,带有
signin.downcase
所以designe不需要知道是否有任何记录是用大写或小写字符存储的。其中([“lower(username)=:value或lower(email)=:value”,{:value=>signin.downcase}])。首先,这部分代码是否对java的where(condition)执行检查?regexp将用两个查询解释“漫长的道路”,designe查询使用

before_save :downcase_fields

def downcase_fields
  self.email.downcase
  self.username.downcase
end