Complete the code to add a validation that ensures the presence of a name.
class User < ApplicationRecord validates :name, [1] end
The presence: true validation ensures that the name field is not empty, protecting data integrity by requiring this important attribute.
Complete the code to validate that the email is unique.
class User < ApplicationRecord validates :email, [1] end
The uniqueness: true validation ensures no two users have the same email, protecting data integrity by avoiding duplicates.
Fix the error in the validation to check that age is a number greater than or equal to 18.
class User < ApplicationRecord validates :age, numericality: { [1]: 18 } end
The option greater_than_or_equal_to correctly checks that age is 18 or older, ensuring valid age data.
Fill both blanks to validate that the username is present and has a minimum length of 5.
class User < ApplicationRecord validates :username, [1], [2] end
Using presence: true ensures the username is not empty, and length: { minimum: 5 } ensures it has at least 5 characters, protecting data quality.
Fill all three blanks to validate that the password is present, has a minimum length of 8, and includes a confirmation field.
class User < ApplicationRecord validates :password, [1], [2], [3] end
The validations ensure the password is entered (presence: true), is at least 8 characters (length: { minimum: 8 }), and matches a confirmation field (confirmation: true), protecting user security and data integrity.