Recall & Review
beginner
What is presence validation in Rails?
Presence validation ensures that a specific attribute is not empty or nil before saving a record in the database.
Click to reveal answer
beginner
How do you add presence validation to a model attribute in Rails?
Use
validates :attribute_name, presence: true inside the model class.Click to reveal answer
beginner
What happens if a presence validation fails when saving a record?
The record is not saved, and error messages are added to the model's
errors collection.Click to reveal answer
intermediate
Can presence validation check multiple attributes at once?
Yes, you can validate multiple attributes by listing them:
validates :name, :email, presence: true.Click to reveal answer
beginner
Why is presence validation important in web applications?
It prevents saving incomplete or invalid data, ensuring the app works correctly and data stays reliable.
Click to reveal answer
Which Rails method is used to enforce presence validation on a model attribute?
✗ Incorrect
The correct syntax is
validates :attribute, presence: true to enforce presence validation.What will happen if a model fails presence validation when calling
save?✗ Incorrect
If presence validation fails, the record is not saved and error messages are added to the model.
Can you validate presence for multiple attributes in one line?
✗ Incorrect
Rails allows validating presence for multiple attributes by listing them in one
validates call.Which of these values will fail presence validation?
✗ Incorrect
Presence validation fails if the attribute is nil or blank (including whitespace-only strings like " "). "Hello" and 0 are present.
Where do you place presence validation code in a Rails app?
✗ Incorrect
Presence validation is declared inside the model class to check data before saving.
Explain how to add presence validation to a Rails model and what it does.
Think about where validations go and what presence means.
You got /3 concepts.
Why is presence validation useful in a web application? Give an example.
Consider what happens if important info is missing.
You got /3 concepts.