0
0
Ruby on Railsframework~10 mins

Schema.rb understanding 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 define a new table in schema.rb.

Ruby on Rails
create_table :users do |[1]|
  t.string :name
end
Drag options to blanks, or click blank then click option'
At
Buser
Ccolumn
Dtable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'table' or 'user' instead of the block variable 't'.
Using 'column' which is not the block variable.
2fill in blank
medium

Complete the code to add a datetime column for tracking record creation.

Ruby on Rails
t.[1] :created_at
Drag options to blanks, or click blank then click option'
Adate
Bdatetime
Ctimestamp
Dtime
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'timestamp' which is not the Rails schema.rb type.
Using 'date' or 'time' which store only part of the information.
3fill in blank
hard

Fix the error in the schema.rb code to add a string column with a limit of 50 characters.

Ruby on Rails
t.string :username, [1]: 50
Drag options to blanks, or click blank then click option'
Alength
Bmax
Climit
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'length' or 'size' which are not valid options here.
Using 'max' which is not recognized.
4fill in blank
hard

Fill both blanks to add an index on the email column and make it unique.

Ruby on Rails
add_index :users, :email, [1]: true, [2]: 'index_users_on_email'
Drag options to blanks, or click blank then click option'
Aunique
Bname
Cindex_name
Dprimary
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'primary' instead of 'unique' for uniqueness.
Using 'index_name' which is not a valid option.
5fill in blank
hard

Fill all three blanks to create a table without the default id column, with a text column, and timestamps.

Ruby on Rails
create_table :posts, id: [1] do |[2]|
  [2].text :content
  [2].timestamps
end
Drag options to blanks, or click blank then click option'
Afalse
Btrue
Ct
Dp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'true' for id which includes the default id column.
Using 'p' as block variable which is uncommon.