Recall & Review
beginner
What is the purpose of column types in Rails migrations?
Column types define the kind of data a database column will store, such as strings, integers, or dates. This helps Rails and the database know how to handle and store the data correctly.
Click to reveal answer
beginner
Name three common column types used in Rails migrations.
Common column types include string (for short text), integer (for whole numbers), and boolean (for true/false values).
Click to reveal answer
beginner
What does the
null: false attribute do in a Rails migration column?It ensures that the column cannot have empty (NULL) values. This means every record must have a value for this column.
Click to reveal answer
beginner
How does the
default attribute work in Rails migrations?The
default attribute sets a value automatically for the column when a new record is created without specifying that column's value.Click to reveal answer
beginner
Why would you use the
timestamps method in a Rails migration?It adds two columns,
created_at and updated_at, which automatically track when a record is created and last updated.Click to reveal answer
Which column type is best for storing a user's email address in Rails?
✗ Incorrect
Email addresses are short text, so the string type is appropriate.
What does setting
null: false on a column do?✗ Incorrect
null: false means the column must have a value; it cannot be empty.Which attribute sets a value automatically if none is provided when creating a record?
✗ Incorrect
The
default attribute sets an automatic value if none is given.What columns does
t.timestamps add in a migration?✗ Incorrect
t.timestamps adds created_at and updated_at columns.Which column type would you use to store true/false values?
✗ Incorrect
Boolean type stores true or false values.
Explain how you would define a column for a user's age that must always have a value and defaults to 18 if not provided.
Think about the type of data, whether it can be empty, and what value to use if none is given.
You got /3 concepts.
Describe the purpose of the
timestamps method in Rails migrations and why it is useful.Consider what information about records is important to keep automatically.
You got /3 concepts.