0
0
Ruby on Railsframework~10 mins

CRUD operations through models 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 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'
Acreate
Bfind
Cupdate
Ddestroy
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.
2fill in blank
medium

Complete 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'
Adelete
Bnew
Ccreate
Dfind
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.
3fill in blank
hard

Fix 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'
Aupdate
Bcreate
Cdestroy
Dfind
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create' which makes a new record instead of updating.
Using 'destroy' which deletes the record.
4fill in blank
hard

Fill 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'
Afind
Bcreate
Cdestroy
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to delete without finding the user first.
Using 'delete' instead of 'destroy' which is the Rails method.
5fill in blank
hard

Fill 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'
Acreate
Bupdate
Cdestroy
Dfind
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of operations.
Using 'find' instead of 'create' to make a new user.