【发布时间】: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