I am trying to set the :host for action mailer default url options.
I have the below set in all the environment files
config.action_mailer.default_url_options = {
:host => "localhost"
}
I want to make it more dynamic by providing the request host.
when I try to set it by
config.action_mailer.default_url_options = {
:host => request.domain
}
OR
config.action_mailer.default_url_options = {
:host => request.env["SERVER_NAME"]
}
It throws error… doesn’t recognize “request” object
is there any way I can set this to the request host, not by hardcoding…?
It is also possible to set a default host that will be used in all mailers by setting the :host option in the default_url_options hash
in an
application_controller.rbadd:Source: https://edgeguides.rubyonrails.org/action_controller_overview.html#default-url-options
Alternatively, you can pass the
requestwhen calling the mailer function from the controllerSource : https://guides.rubyonrails.org/action_mailer_basics.html#generating-urls-with-named-routes