I use rails 2.3.5 and ruby 1.8.7. I am creating a simple TODO manager. Where I have tasks belonging to the user, and the user has many tasks.
I use the acts_as_taggable_on_steroids plugin for tag tasks and the restful_authentication plugin for registering and managing users.
I get a strange error that reads "Unable to duplicate NilClass" in the index action view. This is the controller code -
@tasks = current_user.tasks
The error occurs when I repeat over @tasks in the view. That is, when I do @tasks.each do |task|
Now when I replace the controller code with this
@tasks = Task.find(:all, :conditions => {:user_id => current_user.id})
In fact, you get the same records. This only happens in development mode. I guess this has something to do with caching or loading.
What could be wrong? I encountered this problem for the first time.
EDIT
Well, this is definitely a caching issue. If I make config.cache_classes = true in production.rb, the same error occurs in production mode. But how do I fix this? Because I do not want to restart the server for every change I make in models / controllers.
EDIT
This is what my User model looks like
class User < ActiveRecord::Base has_many :tasks has_many :projects
And this is what the task model looks like.
class Task < ActiveRecord::Base belongs_to :bin belongs_to :project belongs_to :user acts_as_taggable def tag_list super.join(', ') end end
The task controller index method is as follows:
def index @tasks = current_user.tasks respond_to do |format| format.html
Hope this helps.