# Using plugin ssl\_requirement: generate SSL link

**URL:** <https://www.ruby-forum.com/t/using-plugin-ssl-requirement-generate-ssl-link/109308>\
**Category:** Rails\
**Created:** [July 13, 2007, 10:32am UTC](https://www.ruby-forum.com/t/using-plugin-ssl-requirement-generate-ssl-link/109308 "2007-07-13T10:32:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [July 13, 2007, 10:32am UTC](https://www.ruby-forum.com/t/using-plugin-ssl-requirement-generate-ssl-link/109308/1 "2007-07-13T10:32:32Z")

</div>

Hi,  
I am using  
ssl\_requirement([http://dev.rubyonrails.org/svn/rails/plugins/ssl\_requirement/README](http://dev.rubyonrails.org/svn/rails/plugins/ssl_requirement/README))  
to set up SSL access requirement on actions in my controller.

In my webapp’s home page, I provide a login panel for users to login.

I don’t want my home page(the index action) to be accessed through SSL,  
but I do want the login information submitted from the homepage’s login  
panel to be SSL.

But if I don’t make my home page require SSL, user’s login info is  
submited first through non-ssl request(non-securely), then the server  
redirects the browser to submit the information through SSL.

Is there a way for me to generate the SSL-enabled link for login based  
on my ssl\_requirement configuration on login from the controller?  
maybe override the link generation helper?

Thanks.  
Yaxm.

---

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [July 13, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/using-plugin-ssl-requirement-generate-ssl-link/109308/2 "2007-07-13T13:24:11Z")

</div>

El Jul 13, 2007, a las 10:32 AM, Yaxm Y. escribiÃ³:

> SSL,  
> maybe override the link generation helper?  
> Yes, use the secure\_actions plugin, which based on ssl\_requirement:

[http://agilewebdevelopment.com/plugins/secure\_actions](http://agilewebdevelopment.com/plugins/secure_actions)

With that plugin you can configure SSL per action, and is integrated  
with URL generation.

There’s a couple of things to note about it. There’s no API to  
configure an entire controller as secure. I solved that with this  
class method:

# A controller makes this call to declare all their actions run

behind SSL.

# The call must be put at the bottom of the code, so that the

public methods

# are known and returned by public\_instance\_methods.

def self.this\_controller\_only\_responds\_to\_https  
include SecureActions  
require\_ssl \*self.public\_instance\_methods(false).map(&:to\_sym)  
end

The other thing is that the plugin as of revision 14 expects explicit  
controllers and actions in your calls to url\_for (via link\_to or  
whatever). It looks up the pair in a table to figure out whether it  
needs to select “https” as protocol. The attached patch fixes that.

– fxn

---

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [July 13, 2007, 10:24pm UTC](https://www.ruby-forum.com/t/using-plugin-ssl-requirement-generate-ssl-link/109308/3 "2007-07-13T22:24:46Z")

</div>

El Jul 13, 2007, a las 1:23 PM, Xavier N.  
escribió:

> There’s a couple of things to note about it.

I forgot a third detail.

Secure actions are declared with the class method require\_ssl in  
controllers, so you need to load a controller to let the plugin know  
his secure actions, if any.

OK, you know automatic class loading is triggered by const\_missing in  
Rails. Now let’s suppose /public/index has a link to /account/login,  
when you start the server even in production mode the link in the  
home won’t be secure until someone hits AccountController. And that  
argument extends to all the links in the site. The protocol in their  
generation needs to have the corresponding controller class loaded.

That’s why I force class preloading in environment.rb (or  
production.rb if you prefer that file), like this towards the bottom  
of the file:

if RAILS\_ENV == ‘production’  
USE\_SSL = true  
# Trigger controller class loading to execute SSL-related  
# declarations, this way we have the correct links right away.  
require ‘application’  
ActionController::Routing.possible\_controllers.each do |c|  
# known to work without directories  
“#{c.camelize}Controller”.constantize  
end  
end

– fxn

---

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [January 13, 2008, 9:48am UTC](https://www.ruby-forum.com/t/using-plugin-ssl-requirement-generate-ssl-link/109308/4 "2008-01-13T09:48:21Z")

</div>

I tried to force class loading at the end of my environemnt.rb file.

I got a nasty error: â€œA copy of AuthenticatedSystem has been removed  
from the module tree but is still active!â€ whenever I try to access a  
2nd page after I boot up webrick.

AuthenticatedSystem is from plugin acts\_as\_authenticated

Here’s a blog post on the same error:  
[http://blog.railsconsulting.com/2007/2/25/streamlined-plugin-argumenterror](http://blog.railsconsulting.com/2007/2/25/streamlined-plugin-argumenterror)

If I remove the class loading part from my env.rb file, things are fine.

Is there another way to force the class loading?

Thanks.  
Yaxm.

Xavier N. wrote:

> El Jul 13, 2007, a las 1:23 PM, Xavier N.  
> escribiï¿½:  
> There’s a couple of things to note about it.
> 
> I forgot a third detail.
> 
> Secure actions are declared with the class method require\_ssl in  
> controllers, so you need to load a controller to let the plugin know  
> his secure actions, if any.
> 
> OK, you know automatic class loading is triggered by const\_missing in  
> Rails. Now let’s suppose /public/index has a link to /account/login,  
> when you start the server even in production mode the link in the  
> home won’t be secure until someone hits AccountController. And that  
> argument extends to all the links in the site. The protocol in their  
> generation needs to have the corresponding controller class loaded.
> 
> That’s why I force class preloading in environment.rb (or  
> production.rb if you prefer that file), like this towards the bottom  
> of the file:
> 
> if RAILS\_ENV == ‘production’  
> USE\_SSL = true  
> # Trigger controller class loading to execute SSL-related  
> # declarations, this way we have the correct links right away.  
> require ‘application’  
> ActionController::Routing.possible\_controllers.each do |c|  
> # known to work without directories  
> “#{c.camelize}Controller”.constantize  
> end  
> end
> 
> – fxn

---

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [February 13, 2008, 10:05am UTC](https://www.ruby-forum.com/t/using-plugin-ssl-requirement-generate-ssl-link/109308/5 "2008-02-13T10:05:24Z")

</div>

On Feb 13, 2008, at 7:29 , Yaxm Y. wrote:

> I found out that I can’t use “require” but need to use  
> “require\_dependence” in my environment.rb file
> 
> require\_dependency ‘application’  
> ActionController::Routing.possible\_controllers.each do |c|
> 
> # known to work without directories
> 
> “#{c.camelize}Controller”.constantize  
> end

That’s strange, what happended if you used “require”? Where do you  
have that code? Which version of Rails is that?

– fxn

---

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [February 13, 2008, 7:29am UTC](https://www.ruby-forum.com/t/using-plugin-ssl-requirement-generate-ssl-link/109308/6 "2008-02-13T07:29:19Z")

</div>

I found out that I can’t use “require” but need to use  
“require\_dependence” in my environment.rb file

require\_dependency ‘application’  
ActionController::Routing.possible\_controllers.each do |c|

# known to work without directories

“#{c.camelize}Controller”.constantize  
end

Yaxm Y. wrote:

> I tried to force class loading at the end of my environemnt.rb file.
> 
> I got a nasty error: â€œA copy of AuthenticatedSystem has been removed  
> from the module tree but is still active!â€ whenever I try to access a  
> 2nd page after I boot up webrick.
> 
> AuthenticatedSystem is from plugin acts\_as\_authenticated
> 
> Here’s a blog post on the same error:  
> [http://blog.railsconsulting.com/2007/2/25/streamlined-plugin-argumenterror](http://blog.railsconsulting.com/2007/2/25/streamlined-plugin-argumenterror)
> 
> If I remove the class loading part from my env.rb file, things are fine.
> 
> Is there another way to force the class loading?
> 
> Thanks.  
> Yaxm.
> 
> Xavier N. wrote:
> 
> > El Jul 13, 2007, a las 1:23 PM, Xavier N.  
> > escribiï¿½:  
> > There’s a couple of things to note about it.
> > 
> > I forgot a third detail.
> > 
> > Secure actions are declared with the class method require\_ssl in  
> > controllers, so you need to load a controller to let the plugin know  
> > his secure actions, if any.
> > 
> > OK, you know automatic class loading is triggered by const\_missing in  
> > Rails. Now let’s suppose /public/index has a link to /account/login,  
> > when you start the server even in production mode the link in the  
> > home won’t be secure until someone hits AccountController. And that  
> > argument extends to all the links in the site. The protocol in their  
> > generation needs to have the corresponding controller class loaded.
> > 
> > That’s why I force class preloading in environment.rb (or  
> > production.rb if you prefer that file), like this towards the bottom  
> > of the file:
> > 
> > if RAILS\_ENV == ‘production’  
> > USE\_SSL = true  
> > # Trigger controller class loading to execute SSL-related  
> > # declarations, this way we have the correct links right away.  
> > require ‘application’  
> > ActionController::Routing.possible\_controllers.each do |c|  
> > # known to work without directories  
> > “#{c.camelize}Controller”.constantize  
> > end  
> > end
> > 
> > – fxn

---

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [February 15, 2008, 5:55am UTC](https://www.ruby-forum.com/t/using-plugin-ssl-requirement-generate-ssl-link/109308/7 "2008-02-15T05:55:06Z")

</div>

I use rails 1.2.6.

I am using acts\_as\_authenticated plugin.

I place the constanize codes at the bottom of my environment.rb file.

this error only happens when I use ‘require’ instead of  
‘require\_dependency’

ArgumentError (A copy of AuthenticatedSystem has been removed from the  
module tree but is still active!):  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active\_support/dependencies.rb:237:in  
`load_missing_constant' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:452:in`const\_missing’

Xavier N. wrote:

> On Feb 13, 2008, at 7:29 , Yaxm Y. wrote:
> 
> > I found out that I can’t use “require” but need to use  
> > “require\_dependence” in my environment.rb file
> > 
> > require\_dependency ‘application’  
> > ActionController::Routing.possible\_controllers.each do |c|
> > 
> > # known to work without directories
> > 
> > “#{c.camelize}Controller”.constantize  
> > end
> 
> That’s strange, what happended if you used “require”? Where do you  
> have that code? Which version of Rails is that?
> 
> – fxn
