Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to send an email asynchronously using Active Job.
Ruby on Rails
UserMailer.welcome_email(user).[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using deliver_now sends email immediately, not in background.
✗ Incorrect
Using deliver_later queues the email to be sent in the background.
2fill in blank
mediumComplete the code to define a mailer method that sends a welcome email.
Ruby on Rails
def welcome_email(user) @user = user mail(to: @user.email, subject: [1]) end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes causes syntax errors.
✗ Incorrect
The subject option requires a string with quotes.
3fill in blank
hardFix the error in the Active Job class to perform email delivery.
Ruby on Rails
class UserMailerJob < ApplicationJob queue_as :default def perform(user) UserMailer.welcome_email([1]).deliver_now end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @user causes undefined variable error.
✗ Incorrect
The method receives user as argument and should pass it to the mailer.
4fill in blank
hardFill both blanks to enqueue the mailer job with the user argument.
Ruby on Rails
UserMailerJob.[1]([2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using perform_now runs job immediately, not in background.
✗ Incorrect
perform_later enqueues the job; user is the argument passed.
5fill in blank
hardFill all three blanks to create a hash of emails and subjects for users with more than 5 posts.
Ruby on Rails
emails = users.select { |user| user.posts.count [2] 5 and user.active? == [3] }.map { |user| [user.email, [1]] }.to_h Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string 'true' instead of boolean true.
✗ Incorrect
Use user.name for the subject, check if posts count is greater than 5, and active status is true.