Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8765613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:19:38+00:00 2026-06-13T16:19:38+00:00

I checked out the gem called ssl_requirement which enforces SSL on certain actions and

  • 0

I checked out the gem called ssl_requirement which enforces SSL on certain actions and enhances the url and path helpers, it seems promising overall but it’s too outdated and not quite well maintained.

Does anyone know any updated alternatives that provide such convenience:

  1. Require SSL in controllers not in routes file.
  2. Automatically choose https:// on URL and Path helpers without having to ruin the code with: :protocol => 'https'?
  3. Ability to disable the whole SSL enforcement in development
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:19:39+00:00Added an answer on June 13, 2026 at 4:19 pm

    You don’t need a gem – you can just write a little helper to do this.

    in ApplicationController:

    def force_ssl(options = {})
      host = options.delete(:host)
      unless request.ssl? or Rails.env.development?
        redirect_options = {:protocol => 'https://', :status => :moved_permanently}
        redirect_options.merge!(:host => host) if host
        flash.keep
        redirect_to redirect_options and return
      else
        true
      end
    end
    

    And then in your controllers:

    before_filter :force_ssl, :only => [:login]
    

    This does not satisfy your second requirement of automatically choosing the https protocol on path helpers, but that’s not achievable with a controller-specified SSL enforcement, since the route helpers don’t care about what’s happening on a controller level. That is actually mutually exclusive with controller-enforced SSL, because if your routes specify HTTPS, then they won’t resolve a non-HTTPS URL to a controller action, which means that your force_ssl filter would never be hit. You could achieve this by duplicating your routing, however, so that you have both HTTPS-scoped and unscoped routes, with the unscoped routes being defined before the HTTPS-scoped routes, so that the HTTPS-scoped versions assume the helper names. This does mean duplication, though.

    You might be able to achieve that with a little helper method, though. I haven’t tested this, but the concept should work:

    def route_with_https_preference(&block)
      &block.call
      scope :protocol => 'https://', :constraints => { :protocol => 'https://' } do
        instance_eval &block
      end
    end
    
    route_with_https_preference do
      resources :gizmos do
        resources :widgets
      end
    end
    

    You can achieve SSL-scoped routing in your routes file easily enough (see this answer for details), but it does mean that you have to use the _url helpers rather than the _path helpers, as a protocol switch requires a full-qualified URL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've checked out a new branch to install a gem that I often have
I've checked out the block UI plugin in Jquery which puts an overlay over
I checked out the three20 source and was trying to follow this guide to
I checked out TripleDES. It's block size is of 64 bits. Is there any
I checked out a project from TFS I had worked on a while ago,
I checked out a Play application from SVN onto our Ubuntu production server. I've
I've checked out a copy of a project hosted on google code. I'm going
I recently checked out a large C# code base that I will be doing
When updating my checked out directory with TortoiseSVN, some subfolders are listed as Skipped
I just checked out a revision from Subversion to a new folder. Opened the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.