Hey, all! I''m having a url problem that seems like I''m going to overcomplicate it if I don''t just ask what I''m doing wrong... My situation is that I''m testing to see if a visitor is accessing a controller via SSL, and if not, redirect to the same controller via my secure address. This really only amounts to replacing http with https, and so I did the following: redirect_to(:protocol => "https") if !request.ssl? I''m doing this via localhost for now, so I''m not expecting it to actually work. However, I''m getting an incorrect url when I try this: http://localhost:3000httpslocalhost:3000/cart/checkout When I log the url it''s creating with url_for, it''s creating: httpslocalhost:3000/cart/checkout. This seems incorrect... What am I doing wrong? I''ve set only_path to false, but that seems to have no effect. My alternative would be to parse the url and do the replacement and redirect myself, but this seems like it should work! What am I doing wrong? Thanks! Matt
Change "https" to "https://". You can find more here: http://www.michaelgorsuch.org/post/show/22 On 4/28/06, Matt White <stockliasteroid@gmail.com> wrote:> > Hey, all! > > I''m having a url problem that seems like I''m going to overcomplicate > it if I don''t just ask what I''m doing wrong... > > My situation is that I''m testing to see if a visitor is accessing a > controller via SSL, and if not, redirect to the same controller via my > secure address. This really only amounts to replacing http with https, > and so I did the following: > > redirect_to(:protocol => "https") if !request.ssl? > > I''m doing this via localhost for now, so I''m not expecting it to > actually work. However, I''m getting an incorrect url when I try this: > > http://localhost:3000httpslocalhost:3000/cart/checkout > > When I log the url it''s creating with url_for, it''s creating: > httpslocalhost:3000/cart/checkout. This seems incorrect... What am I > doing wrong? I''ve set only_path to false, but that seems to have no > effect. > > My alternative would be to parse the url and do the replacement and > redirect myself, but this seems like it should work! What am I doing > wrong? > > Thanks! > > Matt > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060428/86f296af/attachment.html
On Apr 28, 2006, at 7:09 AM, Matt White wrote:> redirect_to(:protocol => "https") if !request.ssl?Not sure about your error... but I wanted to comment on this line. if !some.cond? could be written as: unless some.cond? It''s easier on the eyes. ;-) redirect_to( :foo ) unless request.ssl? -Robby Robby Russell Founder & Executive Director PLANET ARGON, LLC Ruby on Rails Development, Consulting & Hosting www.planetargon.com www.robbyonrails.com +1 503 445 2457 +1 877 55 ARGON [toll free] +1 815 642 4968 [fax]
Thanks to both of you! The docs were a little unclear on it, because the example showed: proto://host:port/:controller/:action I thought that the :// would be implied in any request, so it seemed odd that I would need to add it. Just didn''t want hack it ;) And thanks for the syntax tip, Robby. I''m still trying to learn the "ruby way", and it always helps to get little tips like that! Matt On 4/28/06, Robby Russell <robby.lists@planetargon.com> wrote:> > > On Apr 28, 2006, at 7:09 AM, Matt White wrote: > > > redirect_to(:protocol => "https") if !request.ssl? > > Not sure about your error... but I wanted to comment on this line. > > if !some.cond? > > could be written as: > > unless some.cond? > > It''s easier on the eyes. ;-) > > redirect_to( :foo ) unless request.ssl? > > -Robby > > > Robby Russell > Founder & Executive Director > > PLANET ARGON, LLC > Ruby on Rails Development, Consulting & Hosting > > www.planetargon.com > www.robbyonrails.com > > +1 503 445 2457 > +1 877 55 ARGON [toll free] > +1 815 642 4968 [fax] > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060428/f0ca39df/attachment.html
Matt - I ran into the same problem when I was first working on SSL. The docs make you think the "//" is implied. Glad to see it''s working. On 4/28/06, Matt White <stockliasteroid@gmail.com> wrote:> > Thanks to both of you! The docs were a little unclear on it, because the > example showed: > > proto://host:port/:controller/:action > > I thought that the :// would be implied in any request, so it seemed odd > that I would need to add it. Just didn''t want hack it ;) > > And thanks for the syntax tip, Robby. I''m still trying to learn the "ruby > way", and it always helps to get little tips like that! > > Matt > > > On 4/28/06, Robby Russell <robby.lists@planetargon.com> wrote: > > > > > > On Apr 28, 2006, at 7:09 AM, Matt White wrote: > > > > > redirect_to(:protocol => "https") if !request.ssl? > > > > Not sure about your error... but I wanted to comment on this line. > > > > if !some.cond? > > > > could be written as: > > > > unless some.cond? > > > > It''s easier on the eyes. ;-) > > > > redirect_to( :foo ) unless request.ssl? > > > > -Robby > > > > > > Robby Russell > > Founder & Executive Director > > > > PLANET ARGON, LLC > > Ruby on Rails Development, Consulting & Hosting > > > > www.planetargon.com > > www.robbyonrails.com > > > > +1 503 445 2457 > > +1 877 55 ARGON [toll free] > > +1 815 642 4968 [fax] > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060428/f27ba47a/attachment.html
Thanks for your blog post, as well... That''s a nice DRY way to do it. I''m going to use a similar solution. Matt On 4/28/06, Michael Gorsuch <michael.gorsuch@gmail.com> wrote:> Matt - I ran into the same problem when I was first working on SSL. > > The docs make you think the "//" is implied. > > Glad to see it''s working. > > > On 4/28/06, Matt White <stockliasteroid@gmail.com> wrote: > > > > Thanks to both of you! The docs were a little unclear on it, because the > example showed: > > > > proto://host:port/:controller/:action > > > > I thought that the :// would be implied in any request, so it seemed odd > that I would need to add it. Just didn''t want hack it ;) > > > > And thanks for the syntax tip, Robby. I''m still trying to learn the "ruby > way", and it always helps to get little tips like that! > > > > > > Matt > > > > > > > > On 4/28/06, Robby Russell <robby.lists@planetargon.com> wrote: > > > > > > On Apr 28, 2006, at 7:09 AM, Matt White wrote: > > > > > > > redirect_to(:protocol => "https") if !request.ssl? > > > > > > Not sure about your error... but I wanted to comment on this line. > > > > > > if !some.cond? > > > > > > could be written as: > > > > > > unless some.cond? > > > > > > It''s easier on the eyes. ;-) > > > > > > redirect_to( :foo ) unless request.ssl? > > > > > > -Robby > > > > > > > > > Robby Russell > > > Founder & Executive Director > > > > > > PLANET ARGON, LLC > > > Ruby on Rails Development, Consulting & Hosting > > > > > > www.planetargon.com > > > www.robbyonrails.com > > > > > > +1 503 445 2457 > > > +1 877 55 ARGON [toll free] > > > +1 815 642 4968 [fax] > > > > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
On Apr 28, 2006, at 7:45 AM, Matt White wrote:> And thanks for the syntax tip, Robby. I''m still trying to learn the > "ruby way", and it always helps to get little tips like that!That''s what I figured... :-) -Robby Robby Russell Founder & Executive Director PLANET ARGON, LLC Ruby on Rails Development, Consulting & Hosting www.planetargon.com www.robbyonrails.com +1 503 445 2457 +1 877 55 ARGON [toll free] +1 815 642 4968 [fax]