Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new user in the seed file.
Ruby on Rails
User.create(name: "Alice", email: "alice@example.com", [1]: "password123")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attribute names like 'pass' or 'pwd' which Rails does not recognize.
✗ Incorrect
The correct attribute for setting a user's password in Rails is password.
2fill in blank
mediumComplete the code to add multiple products in the seed file.
Ruby on Rails
Product.create([{name: "Book", price: 10}, {name: "Pen", price: [1]]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero or negative values which might not make sense for price.
✗ Incorrect
The price for the 'Pen' product is set to 5 as a valid integer value.
3fill in blank
hardFix the error in the seed code to correctly create a category.
Ruby on Rails
Category.[1](name: "Electronics")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new' which does not save the record to the database.
✗ Incorrect
The create method both initializes and saves the record in the database.
4fill in blank
hardFill both blanks to create users with emails and passwords.
Ruby on Rails
User.create(name: "Bob", email: [1], [2]: "securepass")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the email string or using wrong password attribute names.
✗ Incorrect
The email must be a string with quotes, and the password attribute is password.
5fill in blank
hardFill all three blanks to create a product with name, price, and stock quantity.
Ruby on Rails
Product.create(name: [1], price: [2], stock: [3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers with quotes or strings without quotes.
✗ Incorrect
The product name is a string, so it needs quotes. Price and stock are numbers without quotes.