0
0
Ruby on Railsframework~10 mins

Creating migrations in Ruby on Rails - Interactive Practice

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

Complete the code to generate a new migration named AddAgeToUsers.

Ruby on Rails
rails generate [1] AddAgeToUsers
Drag options to blanks, or click blank then click option'
Amigration
Bscaffold
Ccontroller
Dmodel
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'model' or 'controller' instead of 'migration'.
Forgetting to specify the migration name.
2fill in blank
medium

Complete the migration method to add an integer column named age to users table.

Ruby on Rails
def change
  add_column :users, :age, [1]
end
Drag options to blanks, or click blank then click option'
A:boolean
B:string
C:date
D:integer
Attempts:
3 left
💡 Hint
Common Mistakes
Using :string or :boolean instead of :integer.
Omitting the column type.
3fill in blank
hard

Fix the error in the migration to remove the age column from users table.

Ruby on Rails
def change
  [1] :users, :age
end
Drag options to blanks, or click blank then click option'
Aremove_column
Bchange_column
Crename_column
Dadd_column
Attempts:
3 left
💡 Hint
Common Mistakes
Using add_column instead of remove_column.
Using rename_column or change_column incorrectly.
4fill in blank
hard

Fill both blanks to create a migration that adds a string column called email to users table.

Ruby on Rails
def change
  [1] :users, :email, [2]
end
Drag options to blanks, or click blank then click option'
Aadd_column
B:integer
C:string
Dremove_column
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove_column instead of add_column.
Using :integer instead of :string for email.
5fill in blank
hard

Fill all three blanks to create a migration that renames the column username to login in users table.

Ruby on Rails
def change
  [1] :users, [2], [3]
end
Drag options to blanks, or click blank then click option'
Aadd_column
B:username
C:login
Drename_column
Attempts:
3 left
💡 Hint
Common Mistakes
Using add_column instead of rename_column.
Swapping old and new column names.