Devise custom messages when validation fails

后端 未结 4 1385
说谎
说谎 2020-12-15 13:12

I\'m using devise as authentication engine in my app. Is there any way to use custom messages when devise validation fails. Devise provides me with the following message whe

4条回答
  •  星月不相逢
    2020-12-15 13:34

    Please refer to the URL below.

    http://railscasts.com/episodes/210-customizing-devise?view=asciicast

    If the user is signing in, you can edit all the error messages in devise.en.yml under config/locales.

    If you're signing up, Devise provides its own validations out of the box without any customizing. If you want to customize it, you can edit the User model.

    Find devise :validatable and remove the :validatable option. After which, you should be able to use the usual rails validations. Note that this will cause you to have to do all the validations yourself.

    validates_presence_of :password, :message=>"Your custom error message!"

    Some usual validations:

      validates_confirmation_of :password
      validates_presence_of :password, :on => :create
      validates_presence_of :email
      validates_uniqueness_of :email
    

提交回复
热议问题