[Ruby] Set [rails] validation

less than 1 minute read

What is validation

It is a function to check whether the corresponding column contains data when receiving the parameter.

In the example below, check if the name column is nil (no data). If it is nil, it will not be saved.

app/models/user.rb


class User <ApplicationRecord
 
   validates :name, presence: true
  
end