0

I have an HTTP and HTTPS version of my Ruby on Rails running, and if someone accesses through the HTTP one, I want to automatically reload the HTTPS version.

I have done this before on Apache with .httaccess. How can I do it on Rails?

Thanks

3 Answers3

3

In your production.rb file (or whichever env you are forcing ssl) add

config.force_ssl = true
dinomix
  • 956
  • 4
  • 5
2

You can also achieve that by:

class ApplicationController < ActionController::Base
  force_ssl if: :ssl_enabled?

  private

  def ssl_enabled?
    %w(staging production).include?(Rails.env)
  end
end
markets
  • 6,709
  • 1
  • 38
  • 48
1

You can achieve it by putting the below code in config/applcation.rb

#config/application.rb
config.force_ssl = true

Check this blog and this SO post for more info.

Community
  • 1
  • 1
Pavan
  • 33,316
  • 7
  • 50
  • 76