# Add all metods in ssl\_required

**URL:** <https://www.ruby-forum.com/t/add-all-metods-in-ssl-required/147809>\
**Category:** Rails\
**Created:** [September 5, 2008, 4:29pm UTC](https://www.ruby-forum.com/t/add-all-metods-in-ssl-required/147809 "2008-09-05T16:29:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 5, 2008, 4:29pm UTC](https://www.ruby-forum.com/t/add-all-metods-in-ssl-required/147809/1 "2008-09-05T16:29:25Z")

</div>

Can you easily add all methods behind the ssl\_required instead of having  
to add them one by one? Like ssl\_required :all

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 15, 2008, 10:59am UTC](https://www.ruby-forum.com/t/add-all-metods-in-ssl-required/147809/2 "2008-09-15T10:59:20Z")

</div>

You can define a protected method in your controller, which will make  
every action in this controller and all its subclasses only available  
through ssl:

def ssl\_required?  
true  
end

izidor

On 5.9.2008, at 16:29, Pål Bergström wrote:

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 15, 2008, 1:27pm UTC](https://www.ruby-forum.com/t/add-all-metods-in-ssl-required/147809/3 "2008-09-15T13:27:23Z")

</div>

Izidor J. wrote:

> You can define a protected method in your controller, which will make  
> every action in this controller and all its subclasses only available  
> through ssl:
> 
> def ssl\_required?  
> true  
> end
> 
> izidor
> 
> On 5.9.2008, at 16:29, Pï¿½l Bergstrï¿½m wrote:

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [March 26, 2010, 7:28pm UTC](https://www.ruby-forum.com/t/add-all-metods-in-ssl-required/147809/4 "2010-03-26T19:28:21Z")

</div>

class SecureAreaController \< ApplicationController

protected

```
def ssl_required?
  Rails.env.production?
end

```

end

class CreditCardController \< SecureAreaController

…

end

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [December 31, 2008, 5:39am UTC](https://www.ruby-forum.com/t/add-all-metods-in-ssl-required/147809/5 "2008-12-31T05:39:34Z")

</div>

I’m concerned this may not be the best way to go.

in my /app/controllers/application.rb file i’ve added

def ssl\_required?  
return false if ENV[‘RAILS\_ENV’] == true  
end

So that I can still run my application on webrick without https in  
development mode.

But, when I want ssl\_required to work on all my controllers and utilize  
the method below, my ssl\_required? method in the application helper  
doesn’t function as intended. the ssl\_required in the individual  
controller takes precedence.

it is too bad one can’t just add

ssl\_required :all

Does anyone know how to solve both problems in the best way possible?

Thank you!

PÃ¥l BergstrÃ¶m wrote:

> Izidor J. wrote:
> 
> > You can define a protected method in your controller, which will make  
> > every action in this controller and all its subclasses only available  
> > through ssl:
> > 
> > def ssl\_required?  
> > true  
> > end
> > 
> > izidor
> > 
> > On 5.9.2008, at 16:29, Pï¿½l Bergstrï¿½m wrote:
> 
> Thanks 🙂

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [March 27, 2010, 6:42pm UTC](https://www.ruby-forum.com/t/add-all-metods-in-ssl-required/147809/6 "2010-03-27T18:42:18Z")

</div>

Ryan, If you are using or can use passenger to serve your production  
env, then an alternative that would make this a non-issue would be to  
use passenger to serve your development env as well. That way you’d  
be able to use ssl in dev env just as you would in prod env. Another  
benefit would be that you’d also be able to test your prod env setup  
(ie subdomain, virtual-host, passenger/web-server, etc) by having a  
similar setup for your dev env.

Jeff

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [May 18, 2010, 12:04pm UTC](https://www.ruby-forum.com/t/add-all-metods-in-ssl-required/147809/7 "2010-05-18T12:04:03Z")

</div>

I found this fork of ssl\_required that solves this problem, but I  
haven’t tried it yet:

> **[GitHub - bcurren/ssl\_requirement: SSL Requirement plugin](https://github.com/bcurren/ssl_requirement)**
>
> SSL Requirement plugin. Contribute to bcurren/ssl\_requirement development by creating an account on GitHub.

Ryan Wilson wrote:

> it is too bad one can’t just add
> 
> ssl\_required :all
> 
> Does anyone know how to solve both problems in the best way possible?
> 
> Thank you!
