mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-31 05:05:18 +01:00
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
This commit is contained in:
parent
d9355432d7
commit
a7c094b38d
3 changed files with 9 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue