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: <a href="/page/1">1</a> > <a href="/page/2">2</a> I need it to be: <a href="http://customdomain/page/1">1</a> > <a href="http://customdomain/page/2">2</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? 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) %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Chu < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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: > > <a href="/page/1">1</a> > <a href="/page/2">2</a> > > I need it to be: > > <a href="http://customdomain/page/1">1</a> > <a > href="http://customdomain/page/2">2</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? > > 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) %> > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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:> 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 Chu <-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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! On Mon, Jan 19, 2009 at 1:25 PM, Conrad Chu < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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: > > 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 Chu < > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---