简体   繁体   English

Devise 密码重置错误消息出现在 devise_error_messages 但不是 flash?

[英]Devise Password Reset error message appears in the devise_error_messages but not flash?

in my rails 3 app I use devise.在我的 rails 3 应用程序中,我使用 devise。 For the password reset form I have:对于密码重置表格,我有:

<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
    <%= devise_error_messages! %>
    <%= f.hidden_field :reset_password_token %>
    ......

I want to remove the devise_error_message and stick with the rails flash, but that's not working as the errors are not being sent to flash?我想删除 devise_error_message 并坚持使用轨道 flash,但这不起作用,因为错误没有发送到 flash?

<% flash.each do |key, value| %>
<div id="message-drawer">
    <div class="message error">
        <div class="message-inside"><span><%= value %></span>
        </div>
    </div>
</div>
<% end %>   

flash is empty? flash 为空? Why?为什么? Thanks谢谢

By default devise only uses flash messages for sign in and sign out.默认情况下,devise 仅使用 flash 消息进行登录和注销。 Any form errors are printed inline with the form on the next reload.任何表单错误都会在下次重新加载时与表单一起打印。 Consider modifying the controller to generate the appropriate flash messages.考虑修改 controller 以生成适当的 flash 消息。

flash is empty because those are model validation error messages which are printed using the helper method devise_error_message. flash 是空的,因为这些是使用辅助方法 devise_error_message 打印的 model 验证错误消息。 : You can always override it: :你总是可以覆盖它:
https://github.com/plataformatec/devise/blob/master/app/helpers/devise_helper.rb https://github.com/plataformatec/devise/blob/master/app/helpers/devise_helper.rb

But it is a lot easier to customize your devise related messages via the I18n file: config/locales/devise.en.yml但是通过 I18n 文件自定义 devise 相关消息要容易得多: config/locales/devise.en.yml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM