From 5f7f87437c6ed702a4e355e7f4db47b01041c1e8 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Sat, 18 May 2013 13:35:21 -0400 Subject: [PATCH] Fix for topic excerpt being from the wrong post --- app/models/post.rb | 1 + app/serializers/topic_list_item_serializer.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/post.rb b/app/models/post.rb index 475970f136c..96510254839 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -39,6 +39,7 @@ class Post < ActiveRecord::Base SHORT_POST_CHARS = 1200 scope :by_newest, order('created_at desc, id desc') + scope :by_post_number, order('post_number ASC') scope :with_user, includes(:user) scope :public_posts, -> { joins(:topic).where('topics.archetype <> ?', Archetype.private_message) } scope :private_posts, -> { joins(:topic).where('topics.archetype = ?', Archetype.private_message) } diff --git a/app/serializers/topic_list_item_serializer.rb b/app/serializers/topic_list_item_serializer.rb index 0a895a40684..7a994d9cdf6 100644 --- a/app/serializers/topic_list_item_serializer.rb +++ b/app/serializers/topic_list_item_serializer.rb @@ -60,7 +60,7 @@ class TopicListItemSerializer < ListableTopicSerializer end def excerpt - object.posts.first.try(:excerpt,220, strip_links: true) || nil + object.posts.by_post_number.first.try(:excerpt, 220, strip_links: true) || nil end end