From 33d0a6a876b0bc706a53acf15bc3cebdbbefea4a Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Sun, 2 Jun 2013 11:19:37 -0400 Subject: [PATCH] FIX: Safety checks for categories index --- app/models/category_list.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/category_list.rb b/app/models/category_list.rb index 6b2047342..5690130bc 100644 --- a/app/models/category_list.rb +++ b/app/models/category_list.rb @@ -54,8 +54,10 @@ class CategoryList c.displayable_topics = [] topics_in_cat.each do |topic_id| topic = @topics_by_id[topic_id] - topic.category = c - c.displayable_topics << topic + if topic.present? + topic.category = c + c.displayable_topics << topic + end end end end @@ -91,7 +93,7 @@ class CategoryList # Find the appropriate place to insert it: insert_at = nil @categories.each_with_index do |c, idx| - if uncategorized.topics_week > (c.topics_week || 0) + if (uncategorized.topics_week || 0) > (c.topics_week || 0) insert_at = idx break end