0
0
Ruby on Railsframework~5 mins

Column types and attributes in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Aboolean
Binteger
Ctext
Dstring
What does setting null: false on a column do?
ASets a default value
BAllows the column to be empty
CPrevents the column from being empty
DDeletes the column
Which attribute sets a value automatically if none is provided when creating a record?
Anull
Bdefault
Cindex
Dunique
What columns does t.timestamps add in a migration?
Acreated_at and updated_at
Bstart_date and end_date
Cid and uuid
Dname and email
Which column type would you use to store true/false values?
Aboolean
Binteger
Cstring
Ddate
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.