Rails 3 / Devise - 更改密码重置的错误消息

时间:2012-06-20 18:40:17

标签: ruby-on-rails-3 devise

我正在使用Rails 3应用程序,我需要调整密码重新发送视图上的错误消息。如果用户键入电子邮件地址并提交,则当前应用程序将显示以下错误消息:

Email not found

我需要将此错误消息更改为:

We don't have an account with that e-mail address. Maybe you used another address?

我知道您可以在Devise YML文件中对此进行调整,但我不知道该怎么做...有什么建议吗?

工作代码

class PasswordsController < Devise::PasswordsController
  def create
    user = User.find_by_email(params[:user][:email])

    if user.nil?
      flash.now[:notice] = "We don't have an account with that e-mail address. Maybe you used another address?"
    end

    super
  end
end

1 个答案:

答案 0 :(得分:2)

您可以尝试使用before_filter来检查数据库中是否存在该电子邮件,如果没有,它会将您重定向到带有闪存通知的密码重置表单