0
0
Ruby on Railsframework~10 mins

Active Record pattern 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 find a user by id using Active Record.

Ruby on Rails
user = User.[1](1)
Drag options to blanks, or click blank then click option'
Afind
Bget
Csearch
Dlookup
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like 'get' or 'search' which do not exist in Active Record.
2fill in blank
medium

Complete the code to create a new user record with Active Record.

Ruby on Rails
user = User.[1](name: "Alice", email: "alice@example.com")
Drag options to blanks, or click blank then click option'
Amake
Bbuild
Cnew_record
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'build' which only builds but does not save the record.
3fill in blank
hard

Fix the error in the code to update a user's email attribute.

Ruby on Rails
user = User.find(1)
user.[1](email: "new@example.com")
Drag options to blanks, or click blank then click option'
Aupdate
Bchange
Cmodify
Dedit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'change' or 'edit' which are not Active Record methods.
4fill in blank
hard

Fill both blanks to query users with age greater than 30 and order by name.

Ruby on Rails
users = User.where("age [1] ?", 30).[2](:name)
Drag options to blanks, or click blank then click option'
A>
Border
C<
Dsort
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for filtering.
Using 'sort' which is not an Active Record method.
5fill in blank
hard

Fill all three blanks to define a scope named 'active' that selects users with status 'active' and orders by created_at descending.

Ruby on Rails
scope :active, -> { where(status: [1]).[2](created_at: [3]) }
Drag options to blanks, or click blank then click option'
A"active"
Border
C:desc
D"inactive"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'inactive' instead of 'active' for status.
Using incorrect method names for ordering.