Recall & Review
beginner
What does CRUD stand for in Rails models?
CRUD stands for Create, Read, Update, and Delete. These are the four basic actions you can perform on data using Rails models.
Click to reveal answer
beginner
How do you create a new record using a Rails model?
Use
Model.create(attributes) to create and save a new record in one step, or Model.new(attributes) followed by save to create it in two steps.Click to reveal answer
beginner
How do you find a record by its ID in Rails?
Use
Model.find(id) to get a record by its ID. It raises an error if not found. Use Model.find_by(attribute: value) to find by other attributes safely.Click to reveal answer
beginner
How do you update an existing record in Rails?
Find the record first, then use
update(attributes) to change and save it in one step, or assign attributes and call save separately.Click to reveal answer
beginner
How do you delete a record using Rails models?
Use
destroy on a model instance to delete it from the database. For example, record.destroy removes that record.Click to reveal answer
Which method creates and saves a new record in one step?
✗ Incorrect
Model.create creates and saves a new record in one step. Model.new only creates it in memory.What happens if
Model.find(id) does not find a record?✗ Incorrect
Model.find(id) raises an error if the record is not found.Which method updates attributes and saves the record immediately?
✗ Incorrect
update(attributes) changes attributes and saves the record in one step.How do you delete a record from the database?
✗ Incorrect
record.destroy deletes the specific record and runs callbacks.Which method safely finds a record by attribute without raising an error if not found?
✗ Incorrect
Model.find_by returns nil if no record matches, avoiding errors.Explain how to perform all four CRUD operations using Rails models with simple examples.
Think about how you add, look up, change, and remove data in a database using Rails.
You got /4 concepts.
Describe the difference between Model.find and Model.find_by in Rails.
Consider what happens when the record does not exist.
You got /4 concepts.