Hello, I''m sending out an e-mail message to new users of my service. I want to send a particular link in this e-mail but I can''t figure out how to get a complete URL from the url_for method. Is there a way to do this without manually setting the host name? Thank you, -- Miles --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Miles wrote:> Hello, > > I''m sending out an e-mail message to new users of my service. I want > to send a particular link in this e-mail but I can''t figure out how to > get a complete URL from the url_for method. Is there a way to do this > without manually setting the host name? > > Thank you, > -- MilesHave you tried to pass :only_path => false ? Greeting Skade -- 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 -~----------~----~----~----~------~----~------~--~---
I did, what I have in my mail template is this...> <%= url_for :controller => "friend", :action=>"confirm_email",:only_path=> false %>The error I get is this...> Missing host to link to! Please provide :host parameter or set default_url_options[:host]I can pass in the host name, but then when I deploy my production environment I''ll have to remember to go in and change it. I''m looking around now to see if there''s a way to set it just once (maybe in the environment file). If there''s a way Rails can just figure it out, though, that would be ideal. Are there global variables I can access, maybe, that I could use to build out the beginning of the URL (the host name and the application''s path)? -- Miles On Apr 22, 6:50 pm, Florian Gilcher <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Miles wrote: > > Hello, > > > I''m sending out an e-mail message to new users of my service. I want > > to send a particular link in this e-mail but I can''t figure out how to > > get a complete URL from the url_for method. Is there a way to do this > > without manually setting the host name? > > > Thank you, > > -- Miles > > Have you tried to pass :only_path => false ? > > Greeting > Skade > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
wouldn''t request.host work as the host parameter? http://api.rubyonrails.com/classes/ActionController/AbstractRequest.html#M000251 On Apr 22, 6:58 pm, Miles <twitc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I did, what I have in my mail template is this... > > > <%= url_for :controller => "friend", :action=>"confirm_email",:only_path=> false %> > > The error I get is this... > > > Missing host to link to! Please provide :host parameter or set default_url_options[:host] > > I can pass in the host name, but then when I deploy my production > environment I''ll have to remember to go in and change it. I''m looking > around now to see if there''s a way to set it just once (maybe in the > environment file). > > If there''s a way Rails can just figure it out, though, that would be > ideal. Are there global variables I can access, maybe, that I could > use to build out the beginning of the URL (the host name and the > application''s path)? > > -- Miles > > On Apr 22, 6:50 pm, Florian Gilcher <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > Miles wrote: > > > Hello, > > > > I''m sending out an e-mail message to new users of my service. I want > > > to send a particular link in this e-mail but I can''t figure out how to > > > get a complete URL from the url_for method. Is there a way to do this > > > without manually setting the host name? > > > > Thank you, > > > -- Miles > > > Have you tried to pass :only_path => false ? > > > Greeting > > Skade > > > -- > > Posted viahttp://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 Apr 22, 2007, at 10:15 PM, jemminger wrote:> On Apr 22, 6:58 pm, Miles <twitc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On Apr 22, 6:50 pm, Florian Gilcher <rails-mailing-l...@andreas- >> s.net> >> wrote: >> >>> Miles wrote: >>>> Hello, >> >>>> I''m sending out an e-mail message to new users of my service. I >>>> want >>>> to send a particular link in this e-mail but I can''t figure out >>>> how to >>>> get a complete URL from the url_for method. Is there a way to do >>>> this >>>> without manually setting the host name? >> >>>> Thank you, >>>> -- Miles >> >>> Have you tried to pass :only_path => false ? >> >>> Greeting >>> Skade >>> I did, what I have in my mail template is this... >>> >>>> <%= url_for :controller => >>>> "friend", :action=>"confirm_email",:only_path=> false %> >>> >>> The error I get is this... >>> >>>> Missing host to link to! Please provide :host parameter or set >>>> default_url_options[:host] >>> >>> I can pass in the host name, but then when I deploy my production >>> environment I''ll have to remember to go in and change it. I''m >>> looking >>> around now to see if there''s a way to set it just once (maybe in the >>> environment file). >>> >>> If there''s a way Rails can just figure it out, though, that would be >>> ideal. Are there global variables I can access, maybe, that I could >>> use to build out the beginning of the URL (the host name and the >>> application''s path)? >>> >>> -- Miles >>> > wouldn''t request.host work as the host parameter? > http://api.rubyonrails.com/classes/ActionController/ > AbstractRequest.html#M000251If the problem is that your mailer isn''t running as a "request", then why don''t you set a variable in your config/environments/ development.rb (and perhaps also in your production.rb) to get the host where you need it. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@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 -~----------~----~----~----~------~----~------~--~---
Hi,>> Missing host to link to! Please provide :host parameter or set default_url_options[:host] >> > > I can pass in the host name, but then when I deploy my production > environment I''ll have to remember to go in and change it. I''m looking > around now to see if there''s a way to set it just once (maybe in the > environment file). >I had the same problem as you. In the mailer you cannot get the host, because mailer is something belonging to a model, so it''s out of the request/response cycle because of design (that''s the way to go with MVC). You are right that you need to pass the host parameter to your mailer, but in some cases you won''t need to put it on the configuration file. If the mailer gets called from a controller (as a result of one action of the user, for example) then you can just use "#{request.protocol}#{request.host_with_port}" and you''ll get the url for the root of your application. Unfortunately, if you are going to invoke the mailer from a cron or a task, then there''s no request and you should stick to the configuration constant solution. Regards, javier ramirez -- -------- Estamos de estreno... si necesitas llevar el control de tus gastos visita http://www.gastosgem.com !!Es gratis!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yes, the code that sens the mail message in an Mailer object, it''s outside the request/response cycle so it''s request object is always nil. I was thinking about putting this information in the environment somewhere, but then I''d have to change it at deployment time and that would be kind of a drag. Passing the request object to the Mailer from the calling Controller is a good idea! :) I hadn''t thought of that, that will solve this problem, I think. Thank you, -- Miles On Apr 24, 4:54 am, javier ramirez <jrami...-7iWCczGtl7hBDgjK7y7TUQ@public.gmane.org> wrote:> Hi,>> Missing host to link to! Please provide :host parameter or set default_url_options[:host] > > > I can pass in the host name, but then when I deploy my production > > environment I''ll have to remember to go in and change it. I''m looking > > around now to see if there''s a way to set it just once (maybe in the > > environment file). > > I had the same problem as you. In the mailer you cannot get the host, > because mailer is something belonging to a model, so it''s out of the > request/response cycle because of design (that''s the way to go with MVC). > > You are right that you need to pass the host parameter to your mailer, > but in some cases you won''t need to put it on the configuration file. If > the mailer gets called from a controller (as a result of one action of > the user, for example) then you can just use > "#{request.protocol}#{request.host_with_port}" and you''ll get the url > for the root of your application. > > Unfortunately, if you are going to invoke the mailer from a cron or a > task, then there''s no request and you should stick to the configuration > constant solution. > > Regards, > > javier ramirez > > -- > -------- > Estamos de estreno... si necesitas llevar el control de tus gastos visitahttp://www.gastosgem.com!!Es gratis!!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Maybe this.... Write URLs from arbitrary places in your codebase, such as your mailers. Example: class MyMailer include ActionController::UrlWriter default_url_options[:host] = ''www.basecamphq.com'' def signup_url(token) url_for(:controller => ''signup'', action => ''index'', :token => token) end end On Apr 24, 8:09 am, Miles <twitc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes, the code that sens the mail message in an Mailer object, it''s > outside the request/response cycle so it''s request object is always > nil. I was thinking about putting this information in the environment > somewhere, but then I''d have to change it at deployment time and that > would be kind of a drag. > > Passing the request object to the Mailer from the calling Controller > is a good idea! :) I hadn''t thought of that, that will solve this > problem, I think. > > Thank you, > -- Miles > > On Apr 24, 4:54 am, javier ramirez <jrami...-7iWCczGtl7hBDgjK7y7TUQ@public.gmane.org> wrote: > > > Hi,>> Missing host to link to! Please provide :host parameter or set default_url_options[:host] > > > > I can pass in the host name, but then when I deploy my production > > > environment I''ll have to remember to go in and change it. I''m looking > > > around now to see if there''s a way to set it just once (maybe in the > > > environment file). > > > I had the same problem as you. In the mailer you cannot get the host, > > because mailer is something belonging to a model, so it''s out of the > > request/response cycle because of design (that''s the way to go with MVC). > > > You are right that you need to pass the host parameter to your mailer, > > but in some cases you won''t need to put it on the configuration file. If > > the mailer gets called from a controller (as a result of one action of > > the user, for example) then you can just use > > "#{request.protocol}#{request.host_with_port}" and you''ll get the url > > for the root of your application. > > > Unfortunately, if you are going to invoke the mailer from a cron or a > > task, then there''s no request and you should stick to the configuration > > constant solution. > > > Regards, > > > javier ramirez > > > -- > > -------- > > Estamos de estreno... si necesitas llevar el control de tus gastos visitahttp://www.gastosgem.com!!Esgratis!!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---