
ActionMailer
Sending emails, mailers, layouts, attachments, delivery methods, testing emails
1Which command generates a new mailer in a Rails application?
Which command generates a new mailer in a Rails application?
回答
The rails generate mailer command (or rails g mailer) creates a new mailer with the corresponding class in app/mailers, views in app/views, and test files. This command follows Rails conventions and automatically generates the file structure needed to send emails.
2Which class must all mailers inherit from in a Rails application?
Which class must all mailers inherit from in a Rails application?
回答
All Rails mailers inherit from ApplicationMailer, which itself inherits from ActionMailer::Base. ApplicationMailer is created by default in app/mailers and allows defining common configurations for all mailers in the application, such as the default layout or sender address.
3In which directory are email view templates located in a Rails application?
In which directory are email view templates located in a Rails application?
回答
Email view templates are located in app/views/mailer_name/. Each mailer method corresponds to a template (for example welcome_email.html.erb and welcome_email.text.erb). Rails automatically looks for templates matching the mailer method name.
Which method should be used to send an email asynchronously via ActiveJob?
How to define the default sender address for all emails in a mailer?
+15 面接問題