[RUBY] Customization of validation

Overview

While creating a personal app, an event occurred that suddenly made it impossible to register as a group: scream:

The cause was the validation I added to the users model: persevere: (To find the cause, I created the app from scratch and spent 4 days talking about it ...)

I will leave it as a memorandum!

Error status

Group registration screen

スクリーンショット 2020-06-08 17.43.29.png An event occurred in which group registration that was previously possible cannot be performed: zap:

log

スクリーンショット 2020-06-08 17.44.13.png

Looking at the log, the params are ROLLBACKed even though the data is properly retrieved: rolling_eyes: The content of the error is ** invalid **.

Cause

The bad code was the validation I added to the users model: angry:

app/models/user.rb


  validates :password, presence: true, length: {minimum: 8 }

Password 7 characters or less is a description that causes an error.

Perhaps the validation added to the user model made it necessary to get password data when registering a group? ?? Is it? ?? If anyone knows, please let me know: bow_tone1:

Solution

I solved it by adding an option to the validation added to the users model!

app/models/user.rb


  validates :password, presence: true, length: {minimum: 8 },on: :create

Validation is used only when registering as a user! It means that.

Impressions

First of all, it is an event that the cause is found by recreating the application from scratch in the situation where registration is suddenly impossible and the cause is unknown. .. .. It was really painful: sob: I solved it by adding only 11 character code, but I think I got a lot of things in a way: laughing:

reference

● I found a clue to solve password validation. https://qiita.com/noriya1217/items/f0e887f3a7b2c7f83722

● I referred to the validation options. https://qiita.com/Shantti-Y/items/19ea23b81f3421063fc5

Recommended Posts

Customization of validation
Summary of rails validation (for myself)
Validation of log messages using mockito
Implementation of validation using regular expressions
12 of Array
[Rails] Implementation of validation that maintains uniqueness
Rails: Japanese localization of validation messages including devise
RSpec-Results of reviewing the test code for'users validation'
[Rails] Japanese localization of validation error message ~ ja.yml ~
Collective handling of Spring validation errors with @ControllerAdvice
I need validation of Spring Data for Pageable ~