ActionMailer and url_for in helper methods

Hi,

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

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:

1 > 2

I need it to be:

1 > 2

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?

Thanks!
Conrad


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}

end
end

views/user_notifer/changes.rhtml:
<%= breadcrumbs(@page) %>

Use the :host option to make it build the whole URL, like this:

url_for( {:host =>‘customerdomain.com’, :controller => ‘page’, :id => 1
} )

On Sun, Jan 18, 2009 at 2:57 PM, Conrad C. <

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

Ryan W. wrote:

Use the :host option to make it build the whole URL, like this:

url_for( {:host =>‘customerdomain.com’, :controller => ‘page’, :id => 1
} )

On Sun, Jan 18, 2009 at 2:57 PM, Conrad C. <

Perhaps this would be of use:

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

http://dev.rubyonrails.org/ticket/11446

This is also fun:

http://pivotallabs.com/users/nick/blog/articles/281-how-i-learned-to-stop-hating-and-love-action-mailer

HTH!

On Mon, Jan 19, 2009 at 1:25 PM, Conrad C. <