1
 <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
      <p><%= f.label :email %><br />
      <%= f.email_field :email %></p>
      <p><%= f.label :password %><br />
      <%= f.password_field :password %></p>
 <%= end =%>

I am trying to create a basic login form. I want to be able to display an error like "wrong user info" if the username or password is incorrect. I looked at this post here: form_for error messages in Ruby on Rails

but it doesn't seem to work for devise forms?

Community
  • 1
  • 1
Cor
  • 11
  • 1
  • 2

1 Answers1

2

First of all you must put notice alerts

<% if alert %>
  <div id="notice_wrapper">
    <p class="alert"><%= alert %></p>
  </div>
<% elsif notice %>
  <div id="notice_wrapper">
    <p class="notice"><%= notice %></p>
  </div>
<% end %>

i personally use something like this.

To write your own devise errors you must modify it by yourself. Devise errors located at:

config/locales/devise.en.yml
Ruby Doggy
  • 109
  • 5
  • Okay so I would be creating something similar to what you wrote in the config/locales/devise.en.yml file but how would I get the errors to actually display on the page? Thank you by the way. – Cor Dec 17 '15 at 21:37
  • You must have `<%= devise_error_messages! %>` to your views. In top of the form underneath of the form_for line. Also you can modify the div to your css to style the error displaying – Ruby Doggy Dec 17 '15 at 21:58
  • Thank you again. And just to clarify one last time, what file would I be putting the <% if alert %> type code in? My new.html.erb file or something else? – Cor Dec 17 '15 at 22:17
  • to the layouts/application.html.erb file after tag. – Ruby Doggy Dec 17 '15 at 22:42