简体   繁体   中英

client_side_validations and devise error messages

Im validating a form with client side validations and I also have devise, this is in my form:

    <fieldset>
    <div class="control-group">
    <%= f.label :current_password, "Old password:", :class => "control-label" %>
    <div class="controls">
      <%= f.password_field :current_password %>
    </div>
  </div>
  <div class="control-group">
    <%= f.label :password, "New password:", :class => "control-label" %>
    <div class="controls">
      <%= f.password_field :password  %>
    </div>
  </div>
  <div class="control-group">
    <%= f.label :password_confirmation, "New password, again:", :class => "control-label" %>
    <div class="controls">
      <%= f.password_field :password_confirmation  %> 
    </div>
  </div>
</fieldset>

and I have this in my model

validates_presence_of :password, :message => 'required'

validates_presence_of :password_confirmation, :message => 'required'

validates_presence_of :current_password, :message => 'required'

In the end my view shows something like this 在此处输入图片说明

Why are the messages different? I would like to have all my messages to be consistent. How do I change the default message?

Thank you.

Edit your config/locales/en.yml file, like so:

en:
  activerecord:
    errors:
      models:
        user:
          attributes:
            current_password:
              blank: "Required"

Note that you need to replace user with the actual name of your model.

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