0
0
Ruby on Railsframework~10 mins

Model generation 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 model named Product.

Ruby on Rails
rails generate [1] Product
Drag options to blanks, or click blank then click option'
Aview
Bmigration
Cmodel
Dcontroller
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'controller' instead of 'model' will create a controller, not a model.
Using 'migration' alone does not create the model file.
2fill in blank
medium

Complete the code to add a string attribute named 'title' to the Product model during generation.

Ruby on Rails
rails generate model Product [1]:string
Drag options to blanks, or click blank then click option'
Atitle
Bprice
Cdescription
Dquantity
Attempts:
3 left
💡 Hint
Common Mistakes
Using an attribute name other than 'title' will not match the requirement.
Omitting the data type will cause an error.
3fill in blank
hard

Fix the error in the command to generate a model with an integer attribute 'stock'.

Ruby on Rails
rails generate model Inventory [1]:integer
Drag options to blanks, or click blank then click option'
Astock
Bstock_count
Cstock-quantity
Dstock quantity
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'stock-quantity' or 'stock quantity' causes syntax errors.
Using 'stock_count' is valid but not the requested attribute name.
4fill in blank
hard

Fill both blanks to generate a model named Order with a date attribute 'order_date' and a decimal attribute 'total_amount'.

Ruby on Rails
rails generate model [1] [2]:date total_amount:decimal
Drag options to blanks, or click blank then click option'
AOrder
Border_date
COrderDate
DorderDate
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase or PascalCase for attribute names is incorrect.
Using plural model names is not standard.
5fill in blank
hard

Fill all three blanks to generate a model named User with string attributes 'first_name' and 'last_name' and an integer attribute 'age'.

Ruby on Rails
rails generate model [1] [2]:string [3]:string age:integer
Drag options to blanks, or click blank then click option'
AUser
Bfirst_name
Clast_name
Dusername
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'username' instead of 'last_name' does not match the requirement.
Mixing attribute types or names incorrectly.