当我使用生产环境时,Rails不会从文件enviroment.rb中读取代码

发布于 2024-11-25 15:36:58 字数 4048 浏览 1 评论 0原文

我使用的是 Rails 版本 3.0.3。 如果我在开发环境中运行服务器,一切正常,但是当尝试在生产环境中运行时,rails 会跳过从文件 /config/enviroment.rb 读取代码。 我有以下错误:

=> Booting WEBrick
=> Rails 3.0.3 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/herman/WORK/bloomnet/broniszeKwiaty/broniszeKwiaty/broniszeKwiaty/app/models/produkt.rb:10: uninitialized constant Produkt::GRUPY_PRODUKTOWE (NameError)
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:138:in `eager_load!'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:137:in `each'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:137:in `eager_load!'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:135:in `each'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:135:in `eager_load!'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:108:in `eager_load!'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:41
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `run_initializers'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `send'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
        from /home/herman/WORK/bloomnet/broniszeKwiaty/broniszeKwiaty/broniszeKwiaty/config/environment.rb:5
        from /home/herman/WORK/bloomnet/broniszeKwiaty/broniszeKwiaty/broniszeKwiaty/config.ru:3
        from /usr/lib64/ruby/gems/1.8/gems/rack-1.2.2/lib/rack/builder.rb:46:in `instance_eval'
        from /usr/lib64/ruby/gems/1.8/gems/rack-1.2.2/lib/rack/builder.rb:46:in `initialize'
        from /home/herman/WORK/bloomnet/broniszeKwiaty/broniszeKwiaty/broniszeKwiaty/config.ru:1:in `new'
        from /home/herman/WORK/bloomnet/broniszeKwiaty/broniszeKwiaty/broniszeKwiaty/config.ru:1

我的环境.rb 看起来像:

    # Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
BroniszeKwiaty::Application.initialize!


#exceptions
CONTROLLERS_NAMES = {"menu" => "menu_index"}
CONTROLLERS_NAMES_IN_VIEW = {"names" => "imieniny", "produkty" => "towary"}

CONTROLLERS_HIDDEN = [7, 15, 18]

$ZABRONIONE_ROZSZERZENIA = %w{ php rb cgi py shtml pl }

# Ustawienia dla zdjec :


$HEIGHT_MINI3 = 106
$WIDTH_MINI3 = 106

$HEIGHT_CAL = 120
$WIDTH_CAL = 120

$HEIGHT_MINI2 = 163
$WIDTH_MINI2 = 163

$HEIGHT_MINI = 174
$WIDTH_MINI = 174

$WIDTH_MATCHED = 500
$HEIGHT_MATCHED = 300

$WIDTH = 800
$HEIGHT = 600
##################################
$default_cal_path = '/images/cal.png'
$default_cal2_path = '/images/cal2.png'



MENU_URL = { 8 => '/kontakt', 2=> "/informacje", 6=>"/najemcy", 5 =>'/hale', 3 => '/oferta-handlowa', 7 => '/multimedia'} #zastepuje adres /podstrony/:id na wartosc z tablicy (url(/podstrony/2)  => url(/informacje))


$ID_HK = 3 #id hali kwiatow w bazie bronisz
$ID_WK = 8 #id wiaty kwiatowej w bazie bronisz
PELNA_NAZWA_HALI = {3 => "hala kwiatowa",8 => "wiata kwiatowa"}
SKROT_NAZWY_HALI = {3 => "HK",8 => "WK"}

GRUPY_PRODUKTOWE = ["opakowania do kwiatów","kwiaty cięte, zieleń","rośliny doniczkowe", "dodatki kwiatowe"]

非常感谢您的帮助

I am using rails version 3.0.3.
If I run the server in the development environment, everything works ok, but when trying to run in a production environment then rails skip read the code from the file /config/ enviroment.rb.
I have the following error:

=> Booting WEBrick
=> Rails 3.0.3 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/herman/WORK/bloomnet/broniszeKwiaty/broniszeKwiaty/broniszeKwiaty/app/models/produkt.rb:10: uninitialized constant Produkt::GRUPY_PRODUKTOWE (NameError)
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:138:in `eager_load!'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:137:in `each'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:137:in `eager_load!'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:135:in `each'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/engine.rb:135:in `eager_load!'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:108:in `eager_load!'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:41
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `run_initializers'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `send'
        from /usr/local/lib64/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
        from /home/herman/WORK/bloomnet/broniszeKwiaty/broniszeKwiaty/broniszeKwiaty/config/environment.rb:5
        from /home/herman/WORK/bloomnet/broniszeKwiaty/broniszeKwiaty/broniszeKwiaty/config.ru:3
        from /usr/lib64/ruby/gems/1.8/gems/rack-1.2.2/lib/rack/builder.rb:46:in `instance_eval'
        from /usr/lib64/ruby/gems/1.8/gems/rack-1.2.2/lib/rack/builder.rb:46:in `initialize'
        from /home/herman/WORK/bloomnet/broniszeKwiaty/broniszeKwiaty/broniszeKwiaty/config.ru:1:in `new'
        from /home/herman/WORK/bloomnet/broniszeKwiaty/broniszeKwiaty/broniszeKwiaty/config.ru:1

My enviroment.rb looks like:

    # Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
BroniszeKwiaty::Application.initialize!


#exceptions
CONTROLLERS_NAMES = {"menu" => "menu_index"}
CONTROLLERS_NAMES_IN_VIEW = {"names" => "imieniny", "produkty" => "towary"}

CONTROLLERS_HIDDEN = [7, 15, 18]

$ZABRONIONE_ROZSZERZENIA = %w{ php rb cgi py shtml pl }

# Ustawienia dla zdjec :


$HEIGHT_MINI3 = 106
$WIDTH_MINI3 = 106

$HEIGHT_CAL = 120
$WIDTH_CAL = 120

$HEIGHT_MINI2 = 163
$WIDTH_MINI2 = 163

$HEIGHT_MINI = 174
$WIDTH_MINI = 174

$WIDTH_MATCHED = 500
$HEIGHT_MATCHED = 300

$WIDTH = 800
$HEIGHT = 600
##################################
$default_cal_path = '/images/cal.png'
$default_cal2_path = '/images/cal2.png'



MENU_URL = { 8 => '/kontakt', 2=> "/informacje", 6=>"/najemcy", 5 =>'/hale', 3 => '/oferta-handlowa', 7 => '/multimedia'} #zastepuje adres /podstrony/:id na wartosc z tablicy (url(/podstrony/2)  => url(/informacje))


$ID_HK = 3 #id hali kwiatow w bazie bronisz
$ID_WK = 8 #id wiaty kwiatowej w bazie bronisz
PELNA_NAZWA_HALI = {3 => "hala kwiatowa",8 => "wiata kwiatowa"}
SKROT_NAZWY_HALI = {3 => "HK",8 => "WK"}

GRUPY_PRODUKTOWE = ["opakowania do kwiatów","kwiaty cięte, zieleń","rośliny doniczkowe", "dodatki kwiatowe"]

Many thanks for help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沫离伤花 2024-12-02 15:36:58

..有时,Ruby 在决定在哪里寻找常量时会犯错误。您在全局范围内定义了常量 GRUPY_PRODUKTOWE,并且您可能仅使用“GRUPY_PRODUKTOWE”在 Product 模型中访问它。尝试“::GRUPY_PRODUKTOWE”,以便它知道在全局范围内查找它。

.. sometimes, ruby takes a wrong turn when deciding where to look for a constant. You defined the constant GRUPY_PRODUKTOWE globally and you probably access it within the Product model with just "GRUPY_PRODUKTOWE". Try "::GRUPY_PRODUKTOWE" so it knows to look for it in the global scope.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文