simplify logic

This commit is contained in:
r888888888
2017-09-13 14:47:42 -07:00
parent 1f3bafc061
commit 0bfd201973
2 changed files with 3 additions and 9 deletions

View File

@@ -1038,7 +1038,9 @@ class Post < ApplicationRecord
end
def remove_from_favorites
Favorite.delay.purge_post(id, fav_string.scan(/\d+/))
Favorite.delete_all(post_id: id)
user_ids = fav_string.scan(/\d+/)
User.where(:id => user_ids).update_all("favorite_count = favorite_count - 1")
PostVote.where(post_id: id).delete_all
end