0
0
Ruby on Railsframework~10 mins

Changing column types in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to change the column type of 'age' to integer in a Rails migration.

Ruby on Rails
change_column :users, :age, :[1]
Drag options to blanks, or click blank then click option'
Ainteger
Bboolean
Cstring
Ddate
Attempts:
3 left
💡 Hint
Common Mistakes
Using :string instead of :integer
Forgetting the colon before the type
2fill in blank
medium

Complete the migration code to change the 'price' column type to decimal.

Ruby on Rails
change_column :products, :price, :[1]
Drag options to blanks, or click blank then click option'
Ainteger
Bstring
Cdecimal
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using :float which can cause rounding errors
Using :string which is for text
3fill in blank
hard

Fix the error in this migration code to change 'published' column to boolean type.

Ruby on Rails
change_column :articles, :published, [1]
Drag options to blanks, or click blank then click option'
Abool
B:boolean
Cboolean
D:string
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the colon
Using 'bool' which is not a valid Rails type
4fill in blank
hard

Fill both blanks to change the 'start_date' column to datetime and allow null values.

Ruby on Rails
change_column :events, :start_date, :[1], null: [2]
Drag options to blanks, or click blank then click option'
Adatetime
Btrue
Cfalse
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using :string instead of :datetime
Setting null: false when nulls are allowed
5fill in blank
hard

Fill all three blanks to change 'score' column to float, set default to 0.0, and disallow nulls.

Ruby on Rails
change_column :games, :score, :[1], default: [2], null: [3]
Drag options to blanks, or click blank then click option'
Ainteger
B0.0
Cfalse
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using :integer for decimals
Setting null: true when nulls are not allowed