Tom H. wrote:
I am using subdomains in my application to control context. Therefor,
during user registration, password reset, and other actions that require
an email to be sent with a link to be clicked, I need to ensure that the
subdomain appropriate for the user is used.
It seems I need to be able to access request.host from within an
ActionMailer model. But I am not clear how to do this.
You’ll have to supply the request object as a parameter to
mailer calls made in your controllers.
Here’s an outline of one way to do this:
class MyMailer < ActionMailer::Base
def initialize(method_name, request, *params)
@host = request.host_with_port
url_for_without_host(params.update(:host => @host))
alias_method_chain :url_for, :host
def doit(param1, param2)
body :link => url_for(:controller => :user, :action => :rego)
MyMailer.deliver_doit(request, param1, param2)
If you’re not running multi-threaded you can instead
set the mailer default_url_options host in a before_filter,
allowing everything to work automatically.
Rails Wheels - Find Plugins, List & Sell Plugins -