简体   繁体   中英

How to display error messages for a devise form? Ruby on rails

 <%= 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM