# SSL and url\_for

**URL:** <https://www.ruby-forum.com/t/ssl-and-url-for/59087>\
**Category:** Rails\
**Created:** [April 28, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/ssl-and-url-for/59087 "2006-04-28T16:11:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [April 28, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/ssl-and-url-for/59087/1 "2006-04-28T16:11:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [April 28, 2006, 4:20pm UTC](https://www.ruby-forum.com/t/ssl-and-url-for/59087/2 "2006-04-28T16:20:35Z")

</div>

Change “https” to “https://”.

You can find more here:

[http://www.michaelgorsuch.org/post/show/22](http://www.michaelgorsuch.org/post/show/22)

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [April 28, 2006, 4:33pm UTC](https://www.ruby-forum.com/t/ssl-and-url-for/59087/3 "2006-04-28T16:33:02Z")

</div>

On Apr 28, 2006, at 7:09 AM, Matt W. 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 R.  
Founder & Executive Director

PLANET ARGON, LLC  
Ruby on Rails Development, Consulting & Hosting

> **[Planet Argon](https://www.planetargon.com)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[www.robbyonrails.com](http://www.robbyonrails.com)

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4968 [fax]

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [April 28, 2006, 4:54pm UTC](https://www.ruby-forum.com/t/ssl-and-url-for/59087/4 "2006-04-28T16:54:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [April 28, 2006, 5:16pm UTC](https://www.ruby-forum.com/t/ssl-and-url-for/59087/5 "2006-04-28T17:16:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [April 28, 2006, 6:21pm UTC](https://www.ruby-forum.com/t/ssl-and-url-for/59087/6 "2006-04-28T18:21:50Z")

</div>

On Apr 28, 2006, at 7:45 AM, Matt W. 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 R.  
Founder & Executive Director

PLANET ARGON, LLC  
Ruby on Rails Development, Consulting & Hosting

> **[Planet Argon](https://www.planetargon.com)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[www.robbyonrails.com](http://www.robbyonrails.com)

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4968 [fax]

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [April 28, 2006, 5:09pm UTC](https://www.ruby-forum.com/t/ssl-and-url-for/59087/7 "2006-04-28T17:09:56Z")

</div>

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.
