开发者

Rails, Rack:SSL don't work on thin

开发者 https://www.devze.com 2023-04-04 17:16 出处:网络
I want to have https for entire application. I decided to use this gem: https://github.com/tobmatth/rack-ssl-enforcer

I want to have https for entire application.

I decided to use this gem:

https://github.com/tobmatth/rack-ssl-enforcer

However after adding at end

gem 'rack-ssl-enforcer'

in Gemfile and

config.middleware.use Rack::SslEnforcer

in application.rb at end I get error:

/path_to_app/www/.ruby/gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:77:in `send': undefined method `Rac开发者_JAVA百科k' for #<App1::Application:0xf6dcb314> (NoMethodError)
    from /path_to_app/www/.ruby/gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:77:in `method_missing'
    from /path_to_app/www/stolikarnia/config/application.rb:57
    from /path_to_app/www/.ruby/gems/1.8/gems/railties-3.0.9/lib/rails/commands.rb:21:in `require'
    from /path_to_app/www/.ruby/gems/1.8/gems/railties-3.0.9/lib/rails/commands.rb:21
    from script/rails:6:in `require'
    from script/rails:6

As you see from logs i use Rails 3.0.9. I can't upgrade to RoR 3.1.0 because of dependencies.


In your Gemfile change the requirement to

gem 'rack-ssl-enforcer', :require => 'rack/ssl-enforcer'

Then, in your application.rb pass the class name as String to take advantage of lazy evaluation.

config.middleware.use "Rack::SslEnforcer"

As a side note, I encourage you to check https://github.com/josh/rack-ssl. It's the middleware introduced in Rails 3.1. You can already use it in Rails 3.0 with the additional benefit you won't need to change it once you'll upgrade to Rails 3.1.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号