使用Rack :: SslEnforcer初始化时的ArgumentError

时间:2011-02-26 13:57:39

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

尝试使用rack-ssl-enforcer时出现参数错误。 错误来自初始化!在environment.rb中调用。

我使用的是https://github.com/pelle/rack-ssl-enforcer

版本

在application.rb中:

module MyApp
  class Application < Rails::Application

    config.middleware.use Rack::SslEnforcer, :except => ["/login", "/logout", /^\/static\//, "/"]
  end
end

堆栈跟踪如下:

/Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/stack.rb:33:in `initialize': wrong number of arguments (2 for 0) (ArgumentError)
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/stack.rb:33:in `new'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/stack.rb:33:in `build'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/stack.rb:79:in `build'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/railties-3.0.1/lib/rails/application.rb:208:in `inject'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/stack.rb:79:in `each'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/stack.rb:79:in `inject'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/stack.rb:79:in `build'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/railties-3.0.1/lib/rails/application.rb:162:in `build_middleware_stack'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/railties-3.0.1/lib/rails/application/finisher.rb:35
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/railties-3.0.1/lib/rails/initializable.rb:25:in `instance_exec'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/railties-3.0.1/lib/rails/initializable.rb:25:in `run'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/railties-3.0.1/lib/rails/initializable.rb:50:in `run_initializers'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/railties-3.0.1/lib/rails/initializable.rb:49:in `each'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/railties-3.0.1/lib/rails/initializable.rb:49:in `run_initializers'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/railties-3.0.1/lib/rails/application.rb:134:in `initialize!'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/railties-3.0.1/lib/rails/application.rb:77:in `send'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/railties-3.0.1/lib/rails/application.rb:77:in `method_missing'
        from /Users/adamwilson/work/rails/tuteon-rails/trunk/tuteon/config/environment.rb:5
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in `load_dependency'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:591:in `new_constants_in'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in `load_dependency'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require'
        from /Users/adamwilson/work/rails/tuteon-rails/trunk/tuteon/config.ru:3
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval'
        from /Users/adamwilson/work/ruby/gems/.bundler/ruby/1.8/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize'
        from /Users/adamwilson/work/rails/tuteon-rails/trunk/tuteon/config.ru:1:in `new'
        from /Users/adamwilson/work/rails/tuteon-rails/trunk/tuteon/config.ru:1

2 个答案:

答案 0 :(得分:1)

这是因为你的正则表达式没有包含在%r{}

答案 1 :(得分:0)

我唯一能想到的是它没有正确评估为没有parens的函数调用。尝试:

module MyApp
  class Application < Rails::Application

    config.middleware.use(Rack::SslEnforcer, :except => ["/login", "/logout", /^\/static\//, "/"])
  end
end

似乎是一个长镜头。语法看起来有效,并且遵循SslEnforced README中的示例,无法想象为什么它会给你这个错误,而不是挑剔parens并以某种方式误解选项hash。