ActionMailer and url_for in helper methods

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

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

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 Waldron wrote:

Perhaps this would be of use:

http://www.mattberther.com/2008/04/09/generating-urls-with-actionmailer/

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!