0
0
Ruby on Railsframework~10 mins

Column types and attributes 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 add a string column named 'title' to the 'books' table.

Ruby on Rails
add_column :books, :title, :[1]
Drag options to blanks, or click blank then click option'
Astring
Binteger
Cboolean
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' for short strings
Using 'integer' for text columns
2fill in blank
medium

Complete the code to create a 'published' boolean column with a default value of false.

Ruby on Rails
add_column :books, :published, :boolean, default: [1]
Drag options to blanks, or click blank then click option'
Afalse
Btrue
Cnil
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'true' as default
Using 0 instead of false
3fill in blank
hard

Fix the error in the migration to add a 'price' column with decimal type and precision 8, scale 2.

Ruby on Rails
add_column :products, :price, :[1], precision: 8, scale: 2
Drag options to blanks, or click blank then click option'
Astring
Binteger
Cfloat
Ddecimal
Attempts:
3 left
💡 Hint
Common Mistakes
Using float for money
Using integer for decimal values
4fill in blank
hard

Fill both blanks to add a 'username' column that cannot be null and has a unique index.

Ruby on Rails
add_column :users, :username, :[1], null: [2]
add_index :users, :username, unique: true
Drag options to blanks, or click blank then click option'
Astring
Bfalse
Ctrue
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Setting null to true
Using text instead of string
5fill in blank
hard

Fill all three blanks to create a 'created_at' timestamp column that cannot be null and has a default of current time.

Ruby on Rails
add_column :orders, :created_at, :[1], null: [2], default: [3]
Drag options to blanks, or click blank then click option'
Adatetime
Bfalse
C-> { 'CURRENT_TIMESTAMP' }
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using string instead of datetime
Setting null to true
Missing default lambda