【问题标题】:Rails, Rack:SSL don't work on thinRails,Rack:SSL 不适用于瘦身
【发布时间】:2011-09-13 09:53:59
【问题描述】:

我想为整个应用程序使用 https。

我决定使用这个宝石:

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

但是在末尾添加后

gem 'rack-ssl-enforcer'

在 Gemfile 和

config.middleware.use Rack::SslEnforcer

application.rb 最后我得到错误:

/path_to_app/www/.ruby/gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:77:in `send': undefined method `Rack' 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

正如您从日志中看到的,我使用的是 Rails 3.0.9。由于依赖关系,我无法升级到 RoR 3.1.0。

【问题讨论】:

    标签: ruby-on-rails-3 https rack thin


    【解决方案1】:

    在您的Gemfile 中将要求更改为

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

    然后,在您的 application.rb 中将类名传递为 String 以利用惰性求值。

    config.middleware.use "Rack::SslEnforcer"
    

    作为旁注,我鼓励您查看https://github.com/josh/rack-ssl。它是 Rails 3.1 中引入的中间件。您已经可以在 Rails 3.0 中使用它,而且一旦升级到 Rails 3.1,您就无需更改它。

    【讨论】:

    • 谢谢。添加 require 并将 const 更改为 string 后,它可以工作。但是可能没有正确安装证书,因为 Firefox 浏览器没有显示证书已经过验证。
    猜你喜欢
    • 1970-01-01
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    • 2014-02-26
    • 1970-01-01
    相关资源
    最近更新 更多