Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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 ROR设计:允许用户名或电子邮件登录:未定义的局部变量_Ruby_Ruby On Rails 3_Activerecord_Devise - Fatal编程技术网

Ruby ROR设计:允许用户名或电子邮件登录:未定义的局部变量

Ruby ROR设计:允许用户名或电子邮件登录:未定义的局部变量,ruby,ruby-on-rails-3,activerecord,devise,Ruby,Ruby On Rails 3,Activerecord,Devise,我一直在关注Desive github页面上的教程: 我在教程的第二部分中,我们允许用户使用用户名或电子邮件恢复密码,教程中说要将大量代码复制到用户模型中。这是引发错误的行: def self.find_record(login) where(attributes).where(["username = :value OR email = :value", { :value => login }]).first end 这是我得到的错误: NameError (undefined l

我一直在关注Desive github页面上的教程:

我在教程的第二部分中,我们允许用户使用用户名或电子邮件恢复密码,教程中说要将大量代码复制到用户模型中。这是引发错误的行:

def self.find_record(login)
  where(attributes).where(["username = :value OR email = :value", { :value => login }]).first
end
这是我得到的错误:

NameError (undefined local variable or method `attributes' for #<Class:0xa70e1a8>):

app/models/user.rb:63:in `find_record'
app/models/user.rb:44:in `find_recoverable_or_initialize_with_errors'
app/models/user.rb:30:in `send_reset_password_instructions'
namererror(未定义的局部变量或#的“attributes”方法):
app/models/user.rb:63:in'find_record'
app/models/user.rb:44:在'find\u recoverable\u或\u initialize\u with\u errors'中
app/models/user.rb:30:in“发送\重置\密码\说明”

有人知道出现此错误的原因吗?

您没有传入任何属性,并且没有“attributes”类方法,因此
where(attributes)
不起作用。看起来你也不需要。将您的方法更改为:

def self.find_record(login)
  where(["username = :value OR email = :value", { :value => login }]).first
end
不管它值多少钱,我也不知道它在教程中是如何工作的