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. Any help would be greatly appreciated. best, Tom -- 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 -~----------~----~----~----~------~----~------~--~---
Tom Hoen 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 super(method_name, *params) end def url_for(params) url_for_without_host(params.update(:host => @host)) end alias_method_chain :url_for, :host def doit(param1, param2) body :link => url_for(:controller => :user, :action => :rego) end end 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 - http://railswheels.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 -~----------~----~----~----~------~----~------~--~---
Mark Reginald James wrote:> You''ll have to supply the request object as a parameter to > mailer calls made in your controllers.Mark, I appreciate the quick response. Unfortunately, I am using an Observer to initiate the emails. So I don''t think I have access to the request object when the deliver call is made. Is there any other way to access it? -- 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 -~----------~----~----~----~------~----~------~--~---
Tom Hoen wrote:> Mark Reginald James wrote: > >> You''ll have to supply the request object as a parameter to >> mailer calls made in your controllers. > Mark, I appreciate the quick response. > > Unfortunately, I am using an Observer to initiate the emails. So I don''t > think I have access to the request object when the deliver call is made. > > > Is there any other way to access it?Tom, perhaps you can use the second method I described, but make it thread-safe: before_filter ''Thread.current[:host] = request.host_with_port'' def url_for(params) url_for_without_host(params.update(:host => Thread.current[:host])) end alias_method_chain :url_for, :host -- Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.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 -~----------~----~----~----~------~----~------~--~---
Mark Reginald James wrote:> Tom, perhaps you can use the second method I described, > but make it thread-safe: > > before_filter ''Thread.current[:host] = request.host_with_port''Does this describe what your are suggesting: http://www.zorched.net/2007/05/29/making-session-data-available-to-models-in-ruby-on-rails/ It looks like there is some concern about Thread.current and the webserver being used. Do you know if it works with Passenger? Thanks Tom -- 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 -~----------~----~----~----~------~----~------~--~---
On Sat, Jan 10, 2009 at 8:43 AM, Tom Hoen <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> It looks like there is some concern about Thread.current and the > webserver being used. Do you know if it works with Passenger?Interesting question -- I just did a quick test by adding this line Thread.current[:wtf] = request.user_agent to a controller in an app, and fetching a page displaying that variable with three different browsers using Apache 2.2.9 + Passenger 2.0.3 (on OS X). In each case I got the expected (different) user agent string. Probably not definitive, but FWIW! -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hassan Schroeder wrote:> Thread.current[:wtf] = request.user_agent > to a controller in an app, and fetching a page displaying that variable > with three different browsers using Apache 2.2.9 + Passenger 2.0.3 > (on OS X). > > In each case I got the expected (different) user agent string. > > Probably not definitive, but FWIW!Thanks for the test. Now I wonder how it holds up under load. -- 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 -~----------~----~----~----~------~----~------~--~---