简体   繁体   中英

Devise error messages

I have the problem with devise: devise works well, but in devise/registration/new.html.erb I have the next string

<%= devise_error_messages! %>

that string forms error msg like ->

<div id="error_explanation">
  <h2>5 errors prohibited this user from being saved:</h2>
  <ul>
    <li>Email has already been taken</li>
    <li>Password can't be blank</li>
    <li>Phone is not a number</li>
  </ul>
</div>

The msg with all my errors formed on top of my form (over the elements of my form) How do I create an error message beside to the element which this error occurs?

something like this

<div>Email<br />
    **<div class='email_error'>....</div>**
    <div class="field_with_errors">
        <input id="user_email".... />
    </div>
</div>

<div>Name<br />
    **<div class='name_error'>....</div>**
    <div class="field_with_errors">
        <input id="user_name".... />
    </div>
</div>

You can use error_message_on for this: http://apidock.com/rails/ActionView/Helpers/ActiveRecordHelper/error_message_on

You can access the error messages for each fieldname using

if @resource.errors[:field_name]

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