Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new user record with name 'Alice'.
Ruby on Rails
user = User.[1](name: 'Alice')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'find' instead of 'create' to make a new record.
Using 'update' which changes existing records, not create new ones.
✗ Incorrect
The create method creates and saves a new record in the database.
2fill in blank
mediumComplete the code to find a user by id 5.
Ruby on Rails
user = User.[1](5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new' which only initializes but does not fetch from database.
Using 'create' which makes a new record instead of finding.
✗ Incorrect
The find method retrieves a record by its id.
3fill in blank
hardFix the error in updating a user's email to 'new@example.com'.
Ruby on Rails
user = User.find(3) user.[1](email: 'new@example.com')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create' which makes a new record instead of updating.
Using 'destroy' which deletes the record.
✗ Incorrect
The update method changes attributes and saves the record.
4fill in blank
hardFill both blanks to delete a user with id 7.
Ruby on Rails
user = User.[1](7) user.[2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to delete without finding the user first.
Using 'delete' instead of 'destroy' which is the Rails method.
✗ Incorrect
First find the user, then call destroy to delete it.
5fill in blank
hardFill all three blanks to create a user, update their name, and then delete them.
Ruby on Rails
user = User.[1](name: 'Bob') user.[2](name: 'Robert') user.[3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of operations.
Using 'find' instead of 'create' to make a new user.
✗ Incorrect
Create a new user, update the name, then delete the user record.