I am running a rails app on Heroku and running into a problem when a user tries to reset their password. My User model has validates_uniqueness_of :email
and the method to reset their password is
我正在Heroku上运行rails应用程序并在用户尝试重置密码时遇到问题。我的用户模型有validates_uniqueness_of:email和重置密码的方法是
def send_password_reset
generate_token(:password_reset_token)
self.password_reset_sent_at = Time.zone.now
save!
UserMailer.password_reset(self).deliver
end
When I check heroku logs
it is telling me that the save!
is generating ActiveRecord::RecordInvalid (Validation failed: Email has already been taken)
, however I'm not creating a new User or even editing the current user's email field.
When I run it locally everything works fine with no errors.
当我检查heroku日志时,它告诉我保存!正在生成ActiveRecord :: RecordInvalid(验证失败:已经收到电子邮件),但我没有创建新用户,甚至没有编辑当前用户的电子邮件字段。当我在本地运行它时一切正常,没有错误。
2 个解决方案
#1
0
Check if there are more than one user with the same email in the database.
检查数据库中是否有多个用户使用相同的电子邮件。
It's possible that the duplicate was created before the validation was added.
在添加验证之前,可能会创建副本。
#2
0
Look in your Db, use heroku run console
to connect to your application's console and look at the output of User.all
to see if it's there. It won't be the fact that you are running this on Heroku that's causing this error.
查看你的Db,使用heroku运行控制台连接到你的应用程序的控制台,并查看User.all的输出,看看它是否在那里。这不是你在Heroku上运行这个导致这个错误的事实。
#1
0
Check if there are more than one user with the same email in the database.
检查数据库中是否有多个用户使用相同的电子邮件。
It's possible that the duplicate was created before the validation was added.
在添加验证之前,可能会创建副本。
#2
0
Look in your Db, use heroku run console
to connect to your application's console and look at the output of User.all
to see if it's there. It won't be the fact that you are running this on Heroku that's causing this error.
查看你的Db,使用heroku运行控制台连接到你的应用程序的控制台,并查看User.all的输出,看看它是否在那里。这不是你在Heroku上运行这个导致这个错误的事实。