0
0
Ruby on Railsframework~10 mins

Adding and removing columns 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 new column named age of type integer to the users table.

Ruby on Rails
class AddAgeToUsers < ActiveRecord::Migration[6.1]
  def change
    add_column :users, :age, :[1]
  end
end
Drag options to blanks, or click blank then click option'
Astring
Binteger
Cdate
Dboolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string type for numeric data.
Forgetting to specify the column type.
2fill in blank
medium

Complete the code to remove the email column from the customers table.

Ruby on Rails
class RemoveEmailFromCustomers < ActiveRecord::Migration[6.1]
  def change
    remove_column :customers, :[1]
  end
end
Drag options to blanks, or click blank then click option'
Aname
Bphone
Caddress
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Removing the wrong column by mistake.
Forgetting to specify the column name.
3fill in blank
hard

Fix the error in the migration code to add a published_at column of type datetime to the posts table.

Ruby on Rails
class AddPublishedAtToPosts < ActiveRecord::Migration[6.1]
  def change
    add_column :posts, :published_at, :[1]
  end
end
Drag options to blanks, or click blank then click option'
Ainteger
Bstring
Cdatetime
Dboolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using string instead of datetime.
Using integer or boolean incorrectly.
4fill in blank
hard

Fill both blanks to add a price column of type decimal with precision 8 and scale 2 to the products table.

Ruby on Rails
class AddPriceToProducts < ActiveRecord::Migration[6.1]
  def change
    add_column :products, :price, :[1], precision: [2], scale: 2
  end
end
Drag options to blanks, or click blank then click option'
Adecimal
Binteger
C8
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using integer instead of decimal.
Setting wrong precision value.
5fill in blank
hard

Fill all three blanks to create a migration that removes the description column of type text from the items table.

Ruby on Rails
class RemoveDescriptionFromItems < ActiveRecord::Migration[6.1]
  def change
    remove_column :items, :[1], :[2], null: [3]
  end
end
Drag options to blanks, or click blank then click option'
Aname
Bdescription
Ctext
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the column type when removing a column.
Setting incorrect null constraint.