【问题标题】:Rails issue with reloading gems and plugins in development modeRails 在开发模式下重新加载 gems 和插件的问题
【发布时间】:2011-01-05 00:55:26
【问题描述】:

我正在为原型制作一个小 Rails 应用程序。我开始使用一个名为 basejumper

的 starterapp

在快速开始之后,我偶然发现了一个非常烦人的问题。在开发模式下,rails 在第二次请求后崩溃,即我第一次加载页面时,它工作正常,重新加载页面时崩溃

"You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?"

尝试通过 belongs_to 关联访问用户对象时会出现此问题。在视图中,我做了类似的事情,comment.user.login 使视图崩溃:

<% @article.comment_threads.each do |comment| %>
  <div class="comment">
     <%=h comment.body %> | Posted <%=time_ago_in_words(comment.created_at)%>ago
        by <%= comment.user.login %>.</div>
<% end%>

我的课:

class User < ActiveRecord::Base
  acts_as_authentic
  has_many :articles
  has_many :comments

class Comment < ActiveRecord::Base
  acts_as_nested_set :scope => [:commentable_id, :commentable_type] 
  belongs_to :user

class Article < ActiveRecord::Base
  belongs_to :user
  belongs_to :innovation_target
  acts_as_commentable

在我的 development.rb 配置文件中,我放了

config.cache_classes = false

问题消失了,但是每次更改后我都需要重新启动服务器,这基本上是不可行的。我正在使用 Rails 2.3.4。

所以我的问题是,我可以以某种方式强制 rails 在开发模式下重新加载一些/所有 gem 和插件,以便这个问题消失吗?或者你看到其他可能性吗?我正在使用许多不同的插件和 gem,其中包括acts_as_commentable_with_threading、awesome_nested_set 等。

感谢您的帮助。

ps。我确实已经看过 http://www.williambharding.com/blog/rails/automatically-reload-modules-on-change-in-rails/http://nhw.pl/wp/2009/01/07/reloading-your-plugin-in-development-mode 之类的文章,但这些似乎不是诀窍(或者我做错了什么。)

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    经过大量谷歌搜索和检查堆栈跟踪后,我设法解决了这个问题: 在一篇文章http://209.85.129.132/search?q=cache:82jRiVpdYGcJ:www.theirishpenguin.com/2009/01/22/bug-of-the-day-nilinclude-error-with-create_time_zone_conversion_attribute/+create_time_zone_conversion_attribute%3F&cd=1&hl=nl&ct=clnk&gl=be&client=firefox-a(必须使用谷歌缓存,页面暂时未加载)中描述了类似的问题。 cmets中,用户stef建议修改configuration.rb文件

    config.time_zone = ‘UTC’
    to:
    config.active_record.default_timezone = :utc
    

    在灯塔中实际上有一个记录在案的 Rails 问题描述了这一点:https://rails.lighthouseapp.com/projects/8994/tickets/1339-arbase-should-not-be-nuking-its-children-just-because-it-lost-interest

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-10
      • 2011-08-02
      • 2013-04-18
      • 1970-01-01
      • 2012-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多