# How do i enable SSL?

**URL:** <https://www.ruby-forum.com/t/how-do-i-enable-ssl/150327>\
**Category:** Rails\
**Created:** [October 7, 2008, 12:10pm UTC](https://www.ruby-forum.com/t/how-do-i-enable-ssl/150327 "2008-10-07T12:10:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilbertsavier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@gilbertsavier](https://www.ruby-forum.com/u/gilbertsavier)\
**Post date:** [October 7, 2008, 12:10pm UTC](https://www.ruby-forum.com/t/how-do-i-enable-ssl/150327/1 "2008-10-07T12:10:58Z")

</div>

Hello.

I am developing an application using ruby on rails. On of the  
requirements is to use secure socket layer for secure transaction and  
verification of users. How do I Turn on and use SSL on ruby on rails?

–  
Love is the greatest

---

<div class="post-metadata">

**Author:** ![gilbertsavier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@gilbertsavier](https://www.ruby-forum.com/u/gilbertsavier)\
**Post date:** [October 7, 2008, 3:55pm UTC](https://www.ruby-forum.com/t/how-do-i-enable-ssl/150327/2 "2008-10-07T15:55:49Z")

</div>

On Tue, Oct 7, 2008 at 3:10 AM, Gilbert Gift S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hello.
> 
> I am developing an application using ruby on rails. On of the  
> requirements is to use secure socket layer for secure transaction and  
> verification of users. How do I Turn on and use SSL on ruby on rails?

This is something you’d do on the web server level (Apache, Nginx,  
Lighttpd, etc.) not on the Ruby on Rails side of your stack.

Robby

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // 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.

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

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

---

<div class="post-metadata">

**Author:** ![gilbertsavier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@gilbertsavier](https://www.ruby-forum.com/u/gilbertsavier)\
**Post date:** [October 14, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/how-do-i-enable-ssl/150327/3 "2008-10-14T15:44:25Z")

</div>

Robby you are partially true. You do have to make some work on the http  
server side, but also in Rails you must specify that your generated  
links must be using https protocol.

## In Rails 2.1, if I put “include SslRequirement” in the application controller, I get the following error message:

## uninitialized constant ApplicationController::SslRequirement

Is there some updated documentation about that? I have found most  
documentation concerning the plugin version of ssl\_requirement, but that  
back in the days of Rails 1.x. How does it work now with Rails 2.1?

---

<div class="post-metadata">

**Author:** ![gilbertsavier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@gilbertsavier](https://www.ruby-forum.com/u/gilbertsavier)\
**Post date:** [October 14, 2008, 3:52pm UTC](https://www.ruby-forum.com/t/how-do-i-enable-ssl/150327/4 "2008-10-14T15:52:08Z")

</div>

Ok I get it. The ssl\_requirement is still a plugin, I thought it was  
merged inside Rails.

You can install it using script/install plugin ssl\_requirement.

## Also here are some interesting links about some limitations of ssl\_requirement and how to use it:

## [http://siannopollo.blogspot.com/2007/08/rails-and-ssl-https.html](http://siannopollo.blogspot.com/2007/08/rails-and-ssl-https.html) [http://weeatbricks.com/2007/10/31/how-to-use-a-rails-app-with-https/](http://weeatbricks.com/2007/10/31/how-to-use-a-rails-app-with-https/)

---

<div class="post-metadata">

**Author:** ![gilbertsavier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@gilbertsavier](https://www.ruby-forum.com/u/gilbertsavier)\
**Post date:** [October 14, 2008, 6:36pm UTC](https://www.ruby-forum.com/t/how-do-i-enable-ssl/150327/5 "2008-10-14T18:36:51Z")

</div>

I have been playing with this plugin a bit, and I have to say that this  
experience was an absolute failure.

The generated links are completely wrong. How does rails understand  
which actions need to use http and which use https? Currently nothing  
works, I do get redirected to https pages, but for instance the  
root\_path which doesn’t require https gets strangely rendered as it uses  
the name of my rails app instead of the domain name. Why is that?

---

<div class="post-metadata">

**Author:** ![gilbertsavier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@gilbertsavier](https://www.ruby-forum.com/u/gilbertsavier)\
**Post date:** [October 14, 2008, 9:40pm UTC](https://www.ruby-forum.com/t/how-do-i-enable-ssl/150327/6 "2008-10-14T21:40:34Z")

</div>

I’m starting to understand the problems:

- You must define in routes.rb the option :protocol =\> ‘http’ or ‘https’  
so that Rails can generate the correct links.
- On the pages that use https, you must make sure your links are defined  
using some\_name\_url so that non-https links will be generated with  
http://…

I have yet to understand 2 issues I am facing:

- how to define the protocol option with map.resources in routes.rb
- why are links that use http completely wrong. Instead of  
[http://www.mysite.com/logo.png](http://www.mysite.com/logo.png), I get http://my\_rails\_folder/logo.png

Anyone to chip in?

---

<div class="post-metadata">

**Author:** ![gilbertsavier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@gilbertsavier](https://www.ruby-forum.com/u/gilbertsavier)\
**Post date:** [October 14, 2008, 10:34pm UTC](https://www.ruby-forum.com/t/how-do-i-enable-ssl/150327/7 "2008-10-14T22:34:54Z")

</div>

The issue about http links not being correctly rendered is because of  
Nginx, you need to specify the option proxy-redirect off; etc…

I am still facing the issue of defining the protocol for resources  
defined in routes.rb. I don’t know how to do it.

---

<div class="post-metadata">

**Author:** ![gilbertsavier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@gilbertsavier](https://www.ruby-forum.com/u/gilbertsavier)\
**Post date:** [October 26, 2008, 5:43pm UTC](https://www.ruby-forum.com/t/how-do-i-enable-ssl/150327/8 "2008-10-26T17:43:39Z")

</div>

Didn’t this work?

https.resources :forms, :requirements =\> {:protocol =\>  
ROUTES\_PROTOCOL}

On Oct 14, 6:34 pm, Fernando P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![gilbertsavier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@gilbertsavier](https://www.ruby-forum.com/u/gilbertsavier)\
**Post date:** [October 27, 2008, 10:30am UTC](https://www.ruby-forum.com/t/how-do-i-enable-ssl/150327/9 "2008-10-27T10:30:00Z")

</div>

Yeah it worked, make sure to ALWAYS use some\_resource\_url for the  
correct links to be rendered.
