views:

39

answers:

1

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...?

A: 

the problem is these are initializers, they are run when the rails stack loads, and not when you call active mailer.

but you don't have to use the default_url, you can just pass the hostname into the url_for/named routes in each of your mailer views. The default just avoids having to do that.

see http://api.rubyonrails.org/classes/ActionMailer/Base.html section on generating urls.

Doon