Rails - Devise - Error messages when signing in?

Frexuz picture Frexuz · Jan 8, 2011 · Viewed 31.7k times · Source

How can I make f.error_messages work here, or should I use flashes?
If so, what should override in the sessions_controller?

<h2>Create an account</h2>    
<% form_for resource_name, resource, :url => registration_path(resource_name) do |f| %>
  <%= f.error_messages %>
  <p>
    <%= f.label :email %><br />
    <%= f.text_field :email, :class => :big %>
  </p>
  <p>
    <%= f.label :password %><br />
    <%= f.password_field :password, :class => :big %>
  </p>
  <p>
    <%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation, :class => :big %>
  </p>

  <p><%= f.submit "Create", :class => :submit %></p>
<% end %>

PS. f.error_messages for Creating an account works totally fine.

Answer

ffoeg picture ffoeg · Jan 9, 2011

try putting these in your layout:

<%= content_tag(:div, flash[:error], :id => "flash_error") if flash[:error] %>
<%= content_tag(:div, flash[:notice], :id => "flash_notice") if flash[:notice] %>
<%= content_tag(:div, flash[:alert], :id => "flash_alert") if flash[:alert] %>

Login action in Devise sets flash messages, not model Errors.