# SslRequirement module

**URL:** <https://www.ruby-forum.com/t/sslrequirement-module/107857>\
**Category:** Rails\
**Created:** [June 26, 2007, 10:42pm UTC](https://www.ruby-forum.com/t/sslrequirement-module/107857 "2007-06-26T22:42:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dissolved](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b3f665/32.png) [@dissolved](https://www.ruby-forum.com/u/dissolved)\
**Post date:** [June 26, 2007, 10:42pm UTC](https://www.ruby-forum.com/t/sslrequirement-module/107857/1 "2007-06-26T22:42:35Z")

</div>

This is a question is about the SslRequirement rails plugin. However,  
it’s also about core concepts behind ruby modules.

Here’s the code for the plugin.

[http://pastie.caboo.se/73773](http://pastie.caboo.se/73773)

Here’s an example of how you use it.

[http://pastie.caboo.se/73774](http://pastie.caboo.se/73774)

I’ve used this plugin all over the place in my app. But now, I want  
to do some performance testing on the app WITHOUT using https (mainly  
because I don’t have control over port 443 on the test machine).  
Ideally, I want to add a toggle variable to the module that I can set  
from an environment file or application\_controller if I must. What I  
don’t want to do is go around the app and comment out all my  
ssl\_required statements.

I’m at a loss as where to inject this toggle, and whether it should be  
a class variable or class instance variable or maybe something  
completely different. Any and all advice is welcome.

–RYAN

PS - Yes, I’ve double posted this in the rails talk and ruby  
discussion groups.

---

<div class="post-metadata">

**Author:** ![dissolved](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b3f665/32.png) [@dissolved](https://www.ruby-forum.com/u/dissolved)\
**Post date:** [June 27, 2007, 12:37am UTC](https://www.ruby-forum.com/t/sslrequirement-module/107857/2 "2007-06-27T00:37:46Z")

</div>

You could change the third line of the ensure\_proper\_protocol method  
in the plugin like so:

if ssl\_required? && !request.ssl? && RAILS\_ENV == ‘production’

Or you could use your imagination and make some similar kind of  
change somewhere in that method based on an environment variable, a  
constant you set in one of the environment config files, etc.

Basically, you just want that method to not redirect and return  
false, and there a number of ways you could accomplish that.

–  
Benjamin C.  
[http://www.bencurtis.com/](http://www.bencurtis.com/) – blog  
[http://agilewebdevelopment.com/rails-ecommerce](http://agilewebdevelopment.com/rails-ecommerce) – build e-commerce  
sites with Rails

---

<div class="post-metadata">

**Author:** ![dissolved](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b3f665/32.png) [@dissolved](https://www.ruby-forum.com/u/dissolved)\
**Post date:** [June 27, 2007, 2:32pm UTC](https://www.ruby-forum.com/t/sslrequirement-module/107857/3 "2007-06-27T14:32:57Z")

</div>

Sure, you could do a variety of more clever things like stub a method  
in the plugin that can be overridden in the controller, like  
acts\_as\_authenticated does with the authorized method. However, I  
don’t know that doing something like that is really better than a  
simple tweak to the plugin.

---

<div class="post-metadata">

**Author:** ![dissolved](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b3f665/32.png) [@dissolved](https://www.ruby-forum.com/u/dissolved)\
**Post date:** [June 27, 2007, 7:40am UTC](https://www.ruby-forum.com/t/sslrequirement-module/107857/4 "2007-06-27T07:40:18Z")

</div>

Ya, I saw that in another post here. That would work fine, but I feel  
there is a better way – A meta-programming way. Unfortunately, I’m  
still getting my feet wet with injecting class variables / class  
instance variables via eval. I know it’s more advanced then most  
rails talk, but any insight is appreciated.

– RYAN
