关于在轨道上的红宝石上的折射宝石的初始化错误。

时间:2013-12-18 09:43:10

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

我在初始化程序中的refraction.rb文件

Refraction.configure do |request|
  if request.host !~ /^www./
    request.permanent! host: "www.#{request.host}" 
  end
end

我的Environment.rb文件在config

# Load the rails application.
Rails::Initializer.run do |config|
  config.middleware.insert_before(::Rack::Lock, ::Refraction, {})
end

require File.expand_path('../application', __FILE__)

# Initialize the rails application.

我的错误

uninitialized constant Rails (NameError)
  /var/www/vhosts/wiyo.hk/httpdocs/config/environment.rb:2:in `<top (required)>'
  config.ru:3:in `require'
  config.ru:3:in `block in <main>'
  /usr/local/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
  /usr/local/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
  config.ru:1:in `new'
  config.ru:1:in `<main>'
  /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.25/helper-scripts/rack-preloader.rb:105:in `eval'
  /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.25/helper-scripts/rack-preloader.rb:105:in `preload_app'
  /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.25/helper-scripts/rack-preloader.rb:150:in `<module:App>'
  /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.25/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.25/helper-scripts/rack-preloader.rb:28:in `<main>'

我只是想在实际网站加载之前重定向内容。我在之前的问题上了解了折射宝石。我被卡住了。请帮帮我。

1 个答案:

答案 0 :(得分:0)

如果要这样解决,则需要先运行该应用程序,然后再运行该初始化程序。

但是在这种情况下,解决方案可能是将该行放入application.rb 而且由于时间的流逝,Rack::Lock被删除。请改用Rack::Runtime

config.middleware.insert_before(::Rack::Runtime, ::Refraction)