0
0
Ruby on Railsframework~10 mins

Action Mailer setup 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 class inheriting from the correct base class.

Ruby on Rails
class UserMailer < [1]
end
Drag options to blanks, or click blank then click option'
AMailerBase
BApplicationMailer
CActionMailer::Base
DBaseMailer
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent base class like MailerBase.
Inheriting from ApplicationMailer when it is not defined.
2fill in blank
medium

Complete the method to send a welcome email with the correct mail method call.

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

Fix the error in setting the default 'from' email address in the mailer class.

Ruby on Rails
class UserMailer < ActionMailer::Base
  default [1]: 'no-reply@example.com'
end
Drag options to blanks, or click blank then click option'
Afrom
Baddress
Cemail
Dsender
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sender' or 'email' instead of 'from'.
Using 'address' which is not recognized.
4fill in blank
hard

Fill both blanks to configure SMTP settings in the environment file.

Ruby on Rails
config.action_mailer.delivery_method = [1]
config.action_mailer.smtp_settings = [2]
Drag options to blanks, or click blank then click option'
A:smtp
B{ address: 'smtp.example.com', port: 587 }
C:sendmail
D{ address: 'localhost', port: 25 }
Attempts:
3 left
💡 Hint
Common Mistakes
Using :sendmail delivery method but providing SMTP settings.
Providing incorrect keys or values in smtp_settings.
5fill in blank
hard

Fill all three blanks to create a mailer method that sets instance variable, calls mail, and specifies a template.

Ruby on Rails
def notification_email(user)
  [1] = user
  mail(to: user.email, subject: 'Notification') do |format|
    format.[2] [3]
  end
end
Drag options to blanks, or click blank then click option'
A@user
Bhtml
C:notification_email
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using local variable instead of instance variable.
Using wrong format method like 'text' when HTML is expected.
Passing string instead of symbol for template name.