A platform for community discussion. Free, open, simple.
move topic excerpt code to one method to DRY it up and for extensibility
Neil Lalonde8fc128917214
diff --git a/app/models/post.rb b/app/models/post.rbindex 7d8da4859e2..4eb309c7c62 100644--- a/app/models/post.rb+++ b/app/models/post.rb@@ -406,6 +406,10 @@ class Post < ActiveRecord::BasePost.excerpt(cooked, maxlength, options)end+ def excerpt_for_topic+ Post.excerpt(cooked, 220, strip_links: true)+ end+def is_first_post?post_number.blank? ?topic.try(:highest_post_number) == 0 :diff --git a/lib/post_creator.rb b/lib/post_creator.rbindex 522dc288da4..1773adecfab 100644--- a/lib/post_creator.rb+++ b/lib/post_creator.rb@@ -397,7 +397,7 @@ class PostCreatorattrs[:last_posted_at] = @post.created_atattrs[:last_post_user_id] = @post.user_idattrs[:word_count] = (@topic.word_count || 0) + @post.word_count- attrs[:excerpt] = @post.excerpt(220, strip_links: true) if new_topic?+ attrs[:excerpt] = @post.excerpt_for_topic if new_topic?attrs[:bumped_at] = @post.created_at unless @post.no_bumpattrs[:updated_at] = 'now()'@topic.update_columns(attrs)diff --git a/lib/post_revisor.rb b/lib/post_revisor.rbindex 3a1a55d3f12..efa718787d5 100644--- a/lib/post_revisor.rb+++ b/lib/post_revisor.rb@@ -533,7 +533,7 @@ class PostRevisorenddef update_topic_excerpt- excerpt = @post.excerpt(220, strip_links: true)+ excerpt = @post.excerpt_for_topic@topic.update_column(:excerpt, excerpt)if @topic.archetype == "banner"ApplicationController.banner_json_cache.clear