我关注了这个问题 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/