Forum: Ruby on Rails ActionMailer and url_for in helper methods

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Conrad C. (Guest)
on 2009-01-18 22:57

I was wondering how to get url_for to work inside ActionMailer.  I did
research on the web but I can't seem to find something that fits what I

In my application, each user can specify their custom domain to access
their.  I have an ActionMailer that sends them notifications of changes
that occur.  In there, I have a breadcrumbs helper method, which
generages something like:

<a href="/page/1">1</a> &gt;  <a href="/page/2">2</a>

I need it to be:

<a href="http://customdomain/page/1">1</a> &gt;  <a

How do you that?  I tried using default_url_options but it doesn't
affect the helper methods I'm using in the email.  Can somebody help me?



Here's an excerpt of my code:

class UserNotifier < ActionMailer::Base
  helper :application

    # Emails the user the recent changes on the wiki
  def changes(user, page)
    default_url_options[:host] = user.custom_host
    @body => {"page" => page}

<%= breadcrumbs(@page) %>
Ryan W. (Guest)
on 2009-01-19 06:13
(Received via mailing list)
Use the :host option to make it build the whole URL, like this:

url_for( {:host =>'', :controller => 'page', :id => 1
} )

On Sun, Jan 18, 2009 at 2:57 PM, Conrad C. <
Conrad C. (Guest)
on 2009-01-19 21:25
Unfortunately, my email is using helper methods that are also used
throughout the application, so I don't want to hardcode or pass around a
host variable everywhere (because there are a lot of URLs being
generated).  I thought the ActionMailer::Base.default_url_options[:host]
would help but it doesn't seem to work inside the scope of helper

Ryan W. wrote:
> Use the :host option to make it build the whole URL, like this:
> url_for( {:host =>'', :controller => 'page', :id => 1
> } )
> On Sun, Jan 18, 2009 at 2:57 PM, Conrad C. <
Ryan W. (Guest)
on 2009-01-20 00:36
(Received via mailing list)
Perhaps this would be of use:

You may also need to pass ':only_path => false', since this was at one
a requirement with link_to:

This is also fun:


On Mon, Jan 19, 2009 at 1:25 PM, Conrad C. <
This topic is locked and can not be replied to.