nulltek
nulltek

Reputation: 3337

Devise display incorrect username, email, or password error message

This is probably a newb question but I figured I'd ask. I have a Rails 3.2.14 app running Devise 2.1.2. What I'd like to do is display an error message when the user logs in with the incorrect email, username, or password (I'm currently using Devise to auth based on email or username). A flash notice should be displayed in the sessions/new view but not sure what to pull.

I have the following setup in my application.html.erb to display flash notices:

 <% if flash[:notice] %>
          <p class="alert"><%= flash[:notice] %></p>
 <% end %>

But it does not display any error messages when attempting to login with the improper credentials. However when I login successfully it will say successfully signed in via a flash notice/alert.

Currently when you enter the incorrect credentials the screen just refreshes without any flash notice. Any idea on what to include in my devise/sessions/new.html.erb file?

Any help is greatly appreciated. I'm sure it's something simple that I'm missing.

Upvotes: 3

Views: 2173

Answers (1)

usha
usha

Reputation: 29349

Devise uses alert for error messages and notice for success.

Since you are only showing flash[:notice], you only see success message

Try this:

 <% if flash[:notice] %>
          <p class="alert"><%= flash[:notice] %></p>
 <% end %>
 <% if flash[:alert] %>
          <p class="alert"><%= flash[:alert] %></p>
 <% end %>

Upvotes: 5

Related Questions