When using devise to implement a new user registration feature I have given validation, but validation is not applied and I struggled to implement it, so I will leave it as a memorandum.
devise is a gem that makes it easy to implement the authentication function, but it was difficult for me as a beginner to understand what I was doing invisible because the gem worked on its own. This was the reason why it was not applied even though it was validated.
= form_for(@user, url: user_registration_path) do |f|
= f.password_field: password, class: "main__box__bottom__content__group2__form", placeholder: "7 or more single-byte alphanumeric characters",
The conclusion was that the form used password_field, so Rails seems to recognize this input form as a password and automatically perform a simple validation.
Fixed password_fileld to text_field.
= form_for(@user, url: user_user_registration_path) do |f|
= f.text_field :password
end
This recognizes it as a password column.
However, if you validate the addition of the password column of the model, it will be double validated, so Adding devise validation: Remove validatable.
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
# ↑ Delete.
end
Now devise validation is no longer required and password is now given your own customized validation.
-Validation has a priority to refer to Validation given to the text field> devise> Self-made validation It has become. -If you want to apply only custom validation, use text_field and delete: validatable of devise.
https://qiita.com/kouheiszk/items/215afa01eeaadbd99340
Recommended Posts