0
0
Ruby on Railsframework~10 mins

Mailer generation and templates 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 generate a new mailer named UserMailer.

Ruby on Rails
rails generate [1] UserMailer
Drag options to blanks, or click blank then click option'
Amodel
Bcontroller
Cmailer
Dscaffold
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'model' instead of 'mailer' will create a database model, not a mailer.
Using 'controller' creates a controller, not a mailer.
2fill in blank
medium

Complete the mailer method definition to send a welcome email to a user.

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'
A:greeting
B:welcome
C"Hello"
D"Welcome to our site!"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a symbol instead of a string for the subject.
Forgetting quotes around the subject text.
3fill in blank
hard

Fix the error in the mailer view file to correctly display the user's name in the email.

Ruby on Rails
<p>Hello, [1]!</p>
Drag options to blanks, or click blank then click option'
A<% @user.name %>
B<%= @user.name %>
C{{ @user.name }}
D<%= user.name %>
Attempts:
3 left
💡 Hint
Common Mistakes
Using <% %> without equals sign does not output content.
Using wrong variable name without @.
4fill in blank
hard

Fill both blanks to set the default sender email and layout in the mailer class.

Ruby on Rails
class UserMailer < ApplicationMailer
  [1] 'no-reply@example.com'
  [2] 'mailer'
end
Drag options to blanks, or click blank then click option'
Adefault from:
Blayout
Cdefault sender:
Dtemplate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'default sender:' instead of 'default from:'.
Using 'template' instead of 'layout' for layout setting.
5fill in blank
hard

Fill all three blanks to create a mailer method that sends a notification with a subject, recipient, and uses a template.

Ruby on Rails
def notification_email(user)
  @user = user
  mail([1]: @user.email, [2]: [3])
end
Drag options to blanks, or click blank then click option'
Ato
Bsubject
C"You have a new notification"
Dfrom
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'from' and 'to' options.
Not using quotes around the subject string.