I am using a CMS called Radiant (version 0.9.1), Rails 2.3.18 and Ruby 1.8.7. I have to make the routes in this gem use the 'https'. I need to do it in such a way that I won't edit the gem source files itself, but rather override the gem's routes in the extension. How do I do this?
Asked
Active
Viewed 105 times
1 Answers
0
The configuration of the server really depends on what your server stack looks like
To configure your rails application to use SSL you need to force ssl
In your config/environments/production.rb:
config.force_ssl = true
To test ssl locally I would suggest trying thin as a webserver (also put config.force_ssl in development.rb to test this )
Add:
gem 'thin'
To your gemfile and start a thin ssl server:
$ thin start --ssl -p 3000
EDIT Rails 2 :
For Rails 2 this should work:
lib/force_ssl.rb
class ForceSSL
def initialize(app)
@app = app
end
def call(env)
if env['HTTPS'] == 'on' || env['HTTP_X_FORWARDED_PROTO'] == 'https'
@app.call(env)
else
req = Rack::Request.new(env)
[301, { "Location" => req.url.gsub(/^http:/, "https:") }, []]
end
end
end
config/production.rb
config.middleware.use "ForceSSL"
config/application.rb
require File.expand_path('../../lib/force_ssl.rb', __FILE__)
-
Updated the answer, let me know if it works for you. – Laurens Dec 16 '15 at 11:20
-
I put config.middleware.use "ForceSSL" in enviroment.rb coz that's where I put the middlewares. And since I don't have application.rb in config/, I put the require in the environment.rb as well. In starting the thin ssl server, what worked for me was using "script/server thin start". But It gives "Invalid request: Invalid HTTP format, parsing fails." And in the browser, I got SSL Connection Error. "thin start --ssl" alone did not work, it's giving me "server: invalid option: --ssl" – Catherine Dec 17 '15 at 06:41