0
0
Ruby on Railsframework~10 mins

Database folder and migrations 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 generate a new migration file in Rails.

Ruby on Rails
rails generate [1] CreateUsers
Drag options to blanks, or click blank then click option'
Amodel
Bcontroller
Cmigration
Dscaffold
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'model' instead of 'migration' creates a model and migration, not just migration.
Using 'controller' or 'scaffold' generates other files, not just migrations.
2fill in blank
medium

Complete the migration method to add a new column named 'age' of type integer to the 'users' table.

Ruby on Rails
def change
  add_column :users, :age, [1]
end
Drag options to blanks, or click blank then click option'
Astring
Bdate
Cboolean
Dinteger
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' for numeric data.
Using 'boolean' which only stores true or false.
3fill in blank
hard

Fix the error in the migration method to create a 'products' table with a 'name' column of type string.

Ruby on Rails
def change
  create_table :products do |[1]|
    [1].string :name
  end
end
Drag options to blanks, or click blank then click option'
Atable
Bt
Ccolumn
Dp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'table' or 'column' which are not standard block variables.
Using 'p' which is uncommon and confusing.
4fill in blank
hard

Fill both blanks to write a migration that removes the 'age' column from the 'users' table.

Ruby on Rails
def change
  [1]_column :users, :age, :[2]
end
Drag options to blanks, or click blank then click option'
Aremove
Binteger
Cstring
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add_column' instead of 'remove_column'.
Using wrong column type like 'string' for 'age'.
5fill in blank
hard

Fill all three blanks to write a migration that creates a 'posts' table with a 'title' string column and a 'published' boolean column.

Ruby on Rails
def change
  create_table :posts do |[1]|
    [1].[2] :title
    [1].[3] :published
  end
end
Drag options to blanks, or click blank then click option'
At
Bstring
Cboolean
Dp
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong block variable like 'p'.
Mixing up column types like using 'boolean' for 'title'.