ruby-on-railsruby-on-rails-3firefoxrails-ssl-requirement

switching from https to http page in rails 3 results in infinite loop in Firefox


I am using bartt-ssl_requirement for ssl implementation in Rails 3.2.13 in ngnix server

gem 'bartt-ssl_requirement', '~>1.4.0', :require => 'ssl_requirement'

There are some pages which are to be https and some pages which are only http.

So I wrote in application_controller.rb

include SslRequirement

ssl_required :new,create in sessions_controller.rb

ssl_required :show in settings_controller.rb

When I switch from http page to https page, there is no problem.

But when I switch from https to any http, there is a infinite redirection loop in Mozilla .

I also tried with force-non-ssl for the http pages. But no change.

Can anyone help how to fix it either in Rails or ngnix server setting?

Note: This problem occurs only in mozilla. But works fine in Chrome and Internet Explorer


Solution

  • I used the following code to redirect from http to https and vice versa

    def ensure_proper_protocol
         if request.ssl? && !ssl_allowed_action?
    
           redirect_to "http://" + request.host + request.fullpath
         elsif !request.ssl? && ssl_allowed_action?
    
           redirect_to "https://" + request.host + request.fullpath 
         end
      end
    

    And removed the gem 'bartt-ssl_requirement'

    Still the problem did not go.

    Then I simply changed in the production.rb in the config/environments

    config.action_controller.perform_caching = false
    

    Its now working perfectly.