Created
June 9, 2013 20:22
-
-
Save bplexico/5745064 to your computer and use it in GitHub Desktop.
moved HtmlScrubber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#change inside Post | |
def scrubbed_html | |
HtmlScrubber.scrub(cooked) | |
end | |
#updated SearchObserver#after_save method | |
def after_save(obj) | |
if obj.class == Post && obj.cooked_changed? | |
search_data = obj.scrubbed_html << " " << obj.topic.title | |
search_data << " " << obj.topic.category.name if obj.topic.category | |
SearchObserver.update_posts_index(obj.id, search_data) | |
end | |
if obj.class == User && (obj.username_changed? || obj.name_changed?) | |
search_data = obj.username.dup << " " << (obj.name || "") | |
SearchObserver.update_users_index(obj.id, search_data) | |
end | |
if obj.class == Topic && obj.title_changed? | |
if obj.posts | |
post = obj.posts.where(post_number: 1).first | |
if post | |
search_data = post.scrubbed_html << " " << obj.title | |
search_data << " " << obj.category.name if obj.category | |
SearchObserver.update_posts_index(post.id, search_data) | |
end | |
end | |
end | |
if obj.class == Category && obj.name_changed? | |
SearchObserver.update_categories_index(obj.id, obj.name) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment