Rails issue with reloading gems and plugins in development mode
I'm doing a little rails app for a prototype. I started off using a starterapp called basejumper
After a quick start, I stumbled upon a very annoying problem. In development mode, rails crashes after the second request, i.e the first time I load a page, it works fine, a reload of the pages crashes with
"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?"
The issue occurs when trying to access a user object through an belongs_to association. In a view, I do something like, it is the comment.user.login that crashes the view:
<% @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%>
My classes:
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
When in my development.rb config file, I put
config.cache_classes = false
the issue disappears, but leaves me with a server I need to restart after each change, which basically is not workable. I'm using rails 2.3.4.
So my question is, can I somehow force rails to reload some/all gems and plugins in development mode, so that this issue goes away? Or do you see other possibilities? I am using many differ开发者_高级运维ent plugins and gems, including among others acts_as_commentable_with_threading, awesome_nested_set and others.
Thanks for your help.
ps. I did already have a look at articles like http://www.williambharding.com/blog/rails/automatically-reload-modules-on-change-in-rails/ and http://nhw.pl/wp/2009/01/07/reloading-your-plugin-in-development-mode but those don't seem the trick (or I'm doing something wrong.)
After much googling and examining the stack trace, I managed to fix this issue: In an article 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 (have to use google cache, page is not loading for the moment), a similar issue is described. In the comments, user stef suggests to change in the configuration.rb file
config.time_zone = ‘UTC’
to:
config.active_record.default_timezone = :utc
There is actually a documented rails issue in lighthouse describing this: https://rails.lighthouseapp.com/projects/8994/tickets/1339-arbase-should-not-be-nuking-its-children-just-because-it-lost-interest
精彩评论