Ruby ROR设计:允许用户名或电子邮件登录:未定义的局部变量
我一直在关注Desive github页面上的教程: 我在教程的第二部分中,我们允许用户使用用户名或电子邮件恢复密码,教程中说要将大量代码复制到用户模型中。这是引发错误的行: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
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
不管它值多少钱,我也不知道它在教程中是如何工作的