ruby-on-rails - 设计登录失败消息

标签 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

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

最佳答案

设计未设置 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

关于ruby-on-rails - 设计登录失败消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14344228/

相关文章:

ruby-on-rails - curl 请求时,Rails Elasticsearch 不返回任何命中

javascript - RequireJs + Rails 4

ruby-on-rails - 用于 Ruby on Rails 的 Sendgrid API

ruby-on-rails - 为什么 Rails 3 Gemfile 中同时引用了 sqlite3 和 sqlite3-ruby gem?

python - 使用 mechanize python 登录 Instagram

authentication - 在 Meteor 中通过 SMS 登录和注册过程

java - ejb有关角色和身份验证的安全性问题

ruby-on-rails - 设计 - openid + ldap

ruby-on-rails - 通过 Devise for Rails 使用每个用户 `maximum_attempts` 值锁定用户

ruby-on-rails - Rails 的开发环境和生产环境之间有哪些重要区别?