From a7c094b38dd6d8150eaba1205435d6c4bb4cd437 Mon Sep 17 00:00:00 2001 From: bsag Date: Sun, 6 Nov 2005 18:28:00 +0000 Subject: [PATCH] Fixed a weird problem which appeared using Rails 0.14.2 where loading the home page resulted in an error about nil objects. Traced the problem to self.init and altered the code to avoid it. Similar problems still exist on the completed page, and I'm trying to think of ways to work around them. Also improved database performance by using eager loading of associations on the todo/list page. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@161 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/todo_controller.rb | 5 ++++- tracks/app/models/context.rb | 6 ++++-- tracks/config/environment.rb | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index 04179a68..0a6068a9 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -139,6 +139,9 @@ class TodoController < ApplicationController @projects = @user.projects @contexts = @user.contexts @todos = @user.todos - @done = @todos.collect { |x| x.done? ? x:nil }.compact.sort! {|x,y| y.completed <=> x.completed } + @done = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 1", @user.id], :include => [:project], :order => "completed DESC") + # for some reason, this generates an error about anil object under 0.14.2 + #@done = @todos.collect { |x| x.done? ? x:nil }.compact.sort! {|x,y| y.completed <=> x.completed } + end end diff --git a/tracks/app/models/context.rb b/tracks/app/models/context.rb index 30caafbb..67b1483b 100644 --- a/tracks/app/models/context.rb +++ b/tracks/app/models/context.rb @@ -17,12 +17,14 @@ class Context < ActiveRecord::Base end def find_not_done_todos - todos = Todo.find :all, :conditions => "context_id = #{id} AND done = 0", + todos = Todo.find :all, :conditions => "todos.context_id = #{id} AND todos.done = 0", + :include => [:context, :project], :order => "due IS NULL, due ASC, created_at ASC" end def find_done_todos - todos = Todo.find :all, :conditions => "context_id = #{id} AND done = 1", + todos = Todo.find :all, :conditions => "todos.context_id = #{id} AND todos.done = 1", + :include => [:context, :project], :order => "due IS NULL, due ASC, created_at ASC" end diff --git a/tracks/config/environment.rb b/tracks/config/environment.rb index 8d879ef3..620155e5 100644 --- a/tracks/config/environment.rb +++ b/tracks/config/environment.rb @@ -1,6 +1,6 @@ # Be sure to restart your webserver when you modify this file. - # Uncomment below to force Rails into production mode + # (Use only when you can't set environment variables through your web/app server) # ENV['RAILS_ENV'] = 'production'