If necessary, check user messages

I use as the authentication mechanism in my application. Is there a way to use custom messages when validation fails. Devise gives me the following message when the password is empty: Password can't be blank , but I need another message. How can i do this?

+6
source share
4 answers

ActiveRecord en.yml is the answer I would suggest if you want to change Message Validation for development

This is what en.yml looks like

 en: activerecord: errors: models: user: attributes: email: blank: "Please Specify an Email id" taken: "Please use a different Email id" invalid: "Please Specify a valid Email id" password: blank: "Please Specify a Password" confirmation: "Password does not match" password_confirmation: blank: "Please Specify a Password Confirmation" first_name: blank: "Please Specify First Name" last_name: blank: "Please Specify Last Name" pdf: attributes: name: blank: "Please Specify name to PDF" taken: "Please use different name for PDF" attachment: blank: "Please Upload a PDF Attachment" data_element: attributes: name: blank: "Please give Element a desired name" taken: "Already Created Element with given name" color: blank: "Please assign a color to Element" template: attributes: name: blank: "Please Specify a Name" taken: "Please use a different name" 

I advise you to define this method, and not configure the version checking module

Because if you followed the above approach, perhaps you would have skipped checking a place or two

for example, I remove the above validation module, and then replace your own User Model

then the whole check would work, but you would skip the check in Change Password

As a result, you can log in even if the password has never been provided and has never been provided.

Follow this cycle as well.

Greetings

Hi

+22
source

Please refer to the URL below.

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

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

If you sign up, Devise provides its own checks without any configuration. If you want to customize it, you can edit the User model.

Locate devise :validatable and remove the :validatable parameter. After that, you will be able to use conventional rail checks. Please note that this will lead to the need to perform all checks yourself.

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

Some common checks:

  validates_confirmation_of :password validates_presence_of :password, :on => :create validates_presence_of :email validates_uniqueness_of :email 
+2
source

This is not a complete answer, but it seems that it should be resolved using I18n with either internal development keys, or by overriding active record validation error messages for your user model.

Here's a similar question: Come up with attributes for the i18n?

0
source

You can customize your error messages from config / locales / devise.en.yml, but if you want to change the verification message, delete: validatable from Model. You can then change the verification message as before. For instance:

 validates_uniqueness_of :email, :case_sensitive => false, :allow_blank => true, :if => :email_changed? validates_format_of :email, :with => Devise.email_regexp, :allow_blank => true, :if => :email_changed? validates_presence_of :password, :on=>:create validates_confirmation_of :password, :on=>:create validates_length_of :password, :within => Devise.password_length, :allow_blank => true 
0
source

Source: https://habr.com/ru/post/908690/


All Articles