0
0
Ruby on Railsframework~10 mins

Background email delivery 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 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'
Adeliver_later
Bdeliver_now
Csend_now
Dsend_later
Attempts:
3 left
💡 Hint
Common Mistakes
Using deliver_now sends email immediately, not in background.
2fill in blank
medium

Complete 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'
AWelcome to our site!
B"Welcome to our site!"
C:welcome
Duser.email
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes causes syntax errors.
3fill in blank
hard

Fix 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'
Auser
B@user
CUser
Dself
Attempts:
3 left
💡 Hint
Common Mistakes
Using @user causes undefined variable error.
4fill in blank
hard

Fill 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'
Aperform_later
Bperform_now
Cuser
DUser
Attempts:
3 left
💡 Hint
Common Mistakes
Using perform_now runs job immediately, not in background.
5fill in blank
hard

Fill 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'
A"Welcome!"
B>
Ctrue
Duser.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using string 'true' instead of boolean true.