Development errors are displayed twice

Using Devise for authorization, I configured it for authorization by email or login. Invalid driver is deleted. I wrote a confirmation in my user model. I also rewrite the helper helper in 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

In sight (devise / registration / new.html.erb) I am replacing

<%= devise_error_messages! %>

to

<% devise_error_messages! %>

So the problem. When fields are empty (or else), flash errors are displayed. Then I go to the main page and the errors are displayed again. It is displayed only in the registration interface. When authorization is all right. Please, help.

Updated.

partial view (_block_errors.html.erb):

<% flash.each do |name, msg| %>
  <% if msg.class == Array %>
    <% msg.each do |message| %>
      <%= content_tag :p, message, :class => "#{name}" %>
    <% end %>
  <% else %>
    <%= content_tag :p, msg, :class => "#{name}" %>
  <% end %>
<% end %>

In the layout, it is called like:

<%= render 'layouts/block_errors' %>

Solved!

In the overloaded devise_error_messages method! need to replace the line:

flash[:alert] = errors

to

flash.now[:alert] = errors

Hope this helps anyone :)

+1
2

, alert ?

.

<% if flash[:alert] %>
  <p id="notice"><%= flash[:alert] %></p>
<% end %>
+3

, <p id="notice"><%= notice %></p> index.html.erb

+1

All Articles