设计错误显示两次

使用Devise进行授权我将其配置为通过电子邮件或登录进行授权。 已删除Validatable驱动程序。 我在我的用户模型中写了validation。 另外我在app / helpers / devise_helper.rb中覆盖了设计助手:

module DeviseHelper def devise_error_messages! return "" if resource.errors.empty? errors = Array.new resource.errors.each do |field, msg| errors.push(msg) end flash[:alert] = errors end end 

在视图(devise / registrations / new.html.erb)中我替换

  

  

所以,问题。 如果字段为空(或其他),则会显示闪存错误。 然后我转到主页,错误再次出现。 它只出现在注册界面中。 当授权没事的时候。 请帮忙。

更新。

部分视图(_block_errors.html.erb):

     "#{name}" %>    "#{name}" %>   

在布局中,它被称为:

  

解决了!

在重载方法devise_error_messages中! 需要替换字符串:

 flash[:alert] = errors 

 flash.now[:alert] = errors 

希望它可以帮助任何人:)

您确定在应用中的其他任何位置都没有显示alert吗?

应该看起来像这样

 <% if flash[:alert] %> 

<%= flash[:alert] %>

<% end %>

我通过在index.html.erb文件中删除

<%= notice %>

解决了这个问题