move topic excerpt code to one method to DRY it up and for extensibility
This commit is contained in:
parent
3e2ba081d7
commit
8fc1289172
|
@ -406,6 +406,10 @@ class Post < ActiveRecord::Base
|
||||||
Post.excerpt(cooked, maxlength, options)
|
Post.excerpt(cooked, maxlength, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def excerpt_for_topic
|
||||||
|
Post.excerpt(cooked, 220, strip_links: true)
|
||||||
|
end
|
||||||
|
|
||||||
def is_first_post?
|
def is_first_post?
|
||||||
post_number.blank? ?
|
post_number.blank? ?
|
||||||
topic.try(:highest_post_number) == 0 :
|
topic.try(:highest_post_number) == 0 :
|
||||||
|
|
|
@ -397,7 +397,7 @@ class PostCreator
|
||||||
attrs[:last_posted_at] = @post.created_at
|
attrs[:last_posted_at] = @post.created_at
|
||||||
attrs[:last_post_user_id] = @post.user_id
|
attrs[:last_post_user_id] = @post.user_id
|
||||||
attrs[:word_count] = (@topic.word_count || 0) + @post.word_count
|
attrs[: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_bump
|
attrs[:bumped_at] = @post.created_at unless @post.no_bump
|
||||||
attrs[:updated_at] = 'now()'
|
attrs[:updated_at] = 'now()'
|
||||||
@topic.update_columns(attrs)
|
@topic.update_columns(attrs)
|
||||||
|
|
|
@ -533,7 +533,7 @@ class PostRevisor
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_topic_excerpt
|
def update_topic_excerpt
|
||||||
excerpt = @post.excerpt(220, strip_links: true)
|
excerpt = @post.excerpt_for_topic
|
||||||
@topic.update_column(:excerpt, excerpt)
|
@topic.update_column(:excerpt, excerpt)
|
||||||
if @topic.archetype == "banner"
|
if @topic.archetype == "banner"
|
||||||
ApplicationController.banner_json_cache.clear
|
ApplicationController.banner_json_cache.clear
|
||||||
|
|
Loading…
Reference in New Issue