Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 863
nulltek Avatar asked Nov 25 '25 03:11

nulltek


1 Answers

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 %>
like image 85
usha Avatar answered Nov 28 '25 15:11

usha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!