0
0
Ruby on Railsframework~10 mins

Email previews 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 define a mailer preview class in Rails.

Ruby on Rails
class UserMailerPreview < [1]
end
Drag options to blanks, or click blank then click option'
AApplicationMailer
BApplicationController
CActionController::Base
DActionMailer::Preview
Attempts:
3 left
💡 Hint
Common Mistakes
Using ApplicationMailer instead of ActionMailer::Preview
Confusing controllers with mailers
Forgetting to inherit from any class
2fill in blank
medium

Complete the method to preview the welcome email for a user.

Ruby on Rails
def welcome_email
  UserMailer.[1](User.first)
end
Drag options to blanks, or click blank then click option'
Awelcome_email
Bemail_welcome
Cnew_welcome
Dsend_welcome
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names that don't exist in the mailer
Adding extra prefixes or suffixes to the method name
3fill in blank
hard

Fix the error in this preview method to correctly return the mail object.

Ruby on Rails
def notification_email
  mail = UserMailer.notification_email(User.last)
  [1] mail
end
Drag options to blanks, or click blank then click option'
Adeliver_now
Breturn
Csend
Drender
Attempts:
3 left
💡 Hint
Common Mistakes
Calling deliver_now or send which sends the email instead of previewing
Not returning the mail object causing preview to fail
4fill in blank
hard

Fill both blanks to define a preview method that previews an email with a sample user and a token.

Ruby on Rails
def reset_password_email
  user = User.find_by(email: [1])
  UserMailer.reset_password_email(user, [2])
end
Drag options to blanks, or click blank then click option'
A"test@example.com"
B"sample_token_123"
C"user@example.com"
D"token_abc"
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of string literals
Using emails or tokens that don't exist in test data
5fill in blank
hard

Fill all three blanks to create a preview method that sends a newsletter email to a user with a subject.

Ruby on Rails
def newsletter_email
  user = User.find_by(email: [1])
  subject = [2]
  UserMailer.newsletter_email(user, subject: [3])
end
Drag options to blanks, or click blank then click option'
A"subscriber@example.com"
B"Monthly Update"
Csubject
D"Weekly News"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the subject string directly instead of the variable
Using inconsistent variable names