I have a user_mailer with a layout.
For one of my actionmailer methods I want the mailer to NOT use the default layout. But I can't see to find a setting for No Layout.
Any ideas?
Action Mailer is the Rails component that enables applications to send and receive emails. In this chapter, we will see how to send an email using Rails. Let's start creating an emails project using the following command. tp> rails new mailtest. This will create the required framework to proceed.
rails generates a mail preview if you use rails g mailer CustomMailer . You will get a file CustomMailerPreview inside spec/mailers/previews folder. Here you can write your method that will call the mailer and it'll generate a preview.
The default_url_options setting is useful for constructing link URLs in email templates. Usually, the :host , i.e. the fully qualified name of the web server, is needed to be set up with this config option. It has nothing to do with sending emails, it only configures displaying links in the emails.
Simply specify in your mailer:
layout false
You can also append :only => my_action
(or :except
) to limit the methods it applies to, like so:
layout false, :only => 'email_method_no_layout'
(applicable API documentation)
I did it by using a small function, looking at the action name and return the correct mailer layout to be used:
class TransactionMailer < ApplicationMailer layout :select_layout def confirmation_email contact #code end private def select_layout if action_name == 'confirmation_email' false else 'mailer' end end end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With