【问题标题】:Problem running RoR app in production environment在生产环境中运行 RoR 应用程序出现问题
【发布时间】:2011-01-26 16:25:21
【问题描述】:

拥有一个包含“列表”的应用——想想分类广告——每个列表都有一个标签列表。

当我在生产模式下运行应用程序时,以下代码失败,但在开发模式下运行正常

uninitialized constant ActiveRecord::Acts::Taggable::InstanceMethods::TagList
Extracted source (around line #45):

42:         
43:         <span class="listingIndexTags">
44:             Location: [location] | Tags:
45:             <% tag_list = listing.tag_list %>
46:             <% if tag_list != nil %> 
47:                 <% for tag in tag_list %>
48:                     <%= link_to tag.to_s, { :action => "filter_on",

在这个测试用例中我用来启动我的 mongrel 实例的命令行: ruby 脚本/服务器 mongrel -e 生产

默认为端口 3000。我可以访问应用程序中不要调用“listing.tag_list”的其他视图。

“.tag_list”由我在这个应用程序中使用的“acts_as_taggable_on_steroids”提供。它作为 gem 安装。

也许我的环境文件有问题?

这是我的 development.rb 文件

config.cache_classes = false

config.whiny_nils = true

config.action_controller.consider_all_requests_local = true
config.action_view.debug_rjs                         = true
config.action_controller.perform_caching             = false

config.action_mailer.raise_delivery_errors = true

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  ...took these settings out for this post...
}

还有我的 production.rb 文件...

config.cache_classes = true
config.threadsafe!  

config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching             = true

config.cache_store = :mem_cache_store

config.action_mailer.raise_delivery_errors = false

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  ...took these settings out for this post...
}

【问题讨论】:

  • 这几乎肯定与 cache_classes 设置有关。为了缩小范围,如果您在生产中关闭类缓存会发生什么?另外,您使用的是什么版本的 Rails?
  • 如果你删除并重建数据库,开发机器上可能会出现错误。我经常遇到这样的问题,这是因为开发数据库包含满足应用程序某些需求的旧条目,但生产数据库不包含它们,因为它是新鲜的。有时,随着应用程序的增长,我们会更改代码,使其在数据库为空时会失败……如果其他所有方法都失败了,这只是在黑暗中的一枪。
  • 另外,你有什么样的测试(特别是集成)?如果您的测试足够并通过,则不需要上述建议
  • @Randy:我尝试关闭类缓存,并在生产模式下重新启动 Mongrel。症状没有变化。
  • @Stephen:我实际上复制了我的 sqlite3 数据库,并将其粘贴为“production.sqlite3”,因此在这种情况下数据库是相同的。也许这也是我的问题的一部分 - 直接复制数据库,可能是一个很大的禁忌?要回答你的测试问题,你是绝对正确的。我没有涵盖这个的测试 - 事实上,integration_tests.size == 0 目前 - 太糟糕了,我是糟糕的开发人员。所以我需要编写它们并修复它。作为旁注,关于复制数据库的任何其他 cmets?

标签: ruby-on-rails mongrel production-environment


【解决方案1】:

已修复:

好吧,在我不得不(今天)推迟修复这个错误之后,我终于找到了问题的根源。

包含的行: config.threadsafe!

在我的“production.rb”文件中导致它。

I finally found it by:
    1. Making my production and development environment files identical
    2. Line-by-line, changing the production environment file until it either:
      a. The app broke in production mode
      b. I was back to my original production file

无论如何,当我要添加“config.threadsafe!”时线 - 它坏了!我从来没有这么高兴过应用中断。

所以,稍微阅读一下以了解此选项与 Mongrel(如果 Mongrel 甚至相关)的确切作用,我会得到答案。

【讨论】:

  • 干得好。我在这里遇到了同样的问题。该死的 threadsafe! 设置来自我们尝试过的旧 JRuby 部署。
【解决方案2】:

带着同样的问题来到这里,只是想给遇到同样问题的每个人发个便条....我已经通过修复 environment.rb 中的 gems 版本来解决这个问题

改变了这个
config.gem "acts-as-taggable-on", :source => "http://gemcutter.org"

到这个:
config.gem "acts-as-taggable-on", :source => "http://gemcutter.org", :version => '2.0.0.rc1'

并运行 rake gems:install

如果可能的话,我想知道您是否以某种方式在不同的环境中运行不同的 gem。

【讨论】:

    【解决方案3】:

    您的生产服务器上是否安装了acts_as_taggable_on_steroids gem?

    【讨论】:

    • 我愿意。事实证明,当我在“生产”环境中启动 mongrel 时,我的开发机器上也发生了同样的事情,因此没有任何特定于服务器的东西。我的 environment.rb 文件中还有 'config.gem "acts_as_taggable_on_steroids' 行,所以如果我理解正确的话,我希望它适用于所有环境。
    • 那么如果你在服务器上运行gem list 会列出gem 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 2015-05-08
    • 1970-01-01
    相关资源
    最近更新 更多