Reputation: 2753
I have to setup this for my devise usage.
But my app allows users to access through 2 domains.
I wanna set 'config.action_mailer.default_url_options = { :host =>' with the domain that users are accessing to.
How can I do this?
Upvotes: 3
Views: 203
Reputation: 17735
If what you want to achieve is that URLs in the emails you send out are constructed using the current host or domain, the default_url_options approach won't work, because it's only set once at application startup - the request object is not available in that context AFAIK, but only in controller actions.
You could try go generate URLs in your emails in the mailer class without using a default host, something like this (not tested):
class Mailer < ActionMailer::Base
def welcome(user, host)
@url = url_for(host: host, controller: ..., action: ...)
# construct rest of email here
end
end
and then call it from your controller with the appropriate host from the request:
Mailer.welcome(current_user, request.host).deliver
Upvotes: 1