设计登录失败消息

时间:2013-01-15 18:19:51

标签: ruby-on-rails login devise

我遵循了这个问题Devise redirect after login fail并且效果很好,但我收到一条闪光通知告诉我需要登录才能继续,而我需要的信息是密码或电子邮件无效。所以我在CustomFailure中添加了flash通知,如下所示:

    class CustomFailure < Devise::FailureApp
  def redirect_url
    root_path
  end

  def respond
    if http_auth?
      http_auth
    else
      flash[:error] = I18n.t(:invalid, :scope => [ :devise, :failure ])
      redirect
    end
  end
end

现在它向我展示了消息,无效密码和未经验证的消息,如何消除未经身份验证的消息?

1 个答案:

答案 0 :(得分:1)

当登录失败时,Devise不会设置flash[:error],而是flash[:alert],请尝试在您的应用程序中设置此项。

您也可以覆盖方法Devise::FailureApp#i18n_message并让它返回您选择的消息:

class CustomFailure < Devise::FailureApp
  def redirect_url
    root_path
  end

  def i18n_message
    "Hello World" # you might go for something more elaborate here
  end
end
相关问题