fix metatags not updating favgroup post count

This commit is contained in:
Toks
2015-06-29 15:46:29 -04:00
parent 6829a370b2
commit 3cc7dbbedc
2 changed files with 5 additions and 16 deletions

View File

@@ -42,12 +42,9 @@ class FavoriteGroupsController < ApplicationController
end
def update
# need to do this in order for synchronize! to work correctly
@favorite_group = FavoriteGroup.find(params[:id])
check_privilege(@favorite_group)
@favorite_group.attributes = params[:favorite_group]
@favorite_group.synchronize
@favorite_group.save
@favorite_group.update_attributes(params[:favorite_group])
unless @favorite_group.errors.any?
flash[:notice] = "Favorite group updated"
end

View File

@@ -10,7 +10,7 @@ class FavoriteGroup < ActiveRecord::Base
before_validation :strip_name
validate :creator_can_create_favorite_groups, :on => :create
validate :validate_number_of_posts
after_create :synchronize!
before_save :update_post_count
attr_accessible :name, :post_ids, :post_id_array, :as => [:member, :gold, :platinum, :builder, :contributor, :janitor, :moderator, :admin, :default]
module SearchMethods
@@ -149,32 +149,24 @@ class FavoriteGroup < ActiveRecord::Base
@post_id_array_was = nil
end
def synchronize
added = post_id_array - post_id_array_was
removed = post_id_array_was - post_id_array
def update_post_count
normalize_post_ids
clear_post_id_array
self.post_count = post_id_array.size
end
def synchronize!
synchronize
save
end
def add!(post)
return if contains?(post.id)
update_attributes(:post_ids => add_number_to_string(post.id, post_ids), :post_count => post_count + 1)
clear_post_id_array
update_attributes(:post_ids => add_number_to_string(post.id, post_ids))
end
def remove!(post)
return unless contains?(post.id)
update_attributes(:post_ids => remove_number_from_string(post.id, post_ids), :post_count => post_count - 1)
clear_post_id_array
update_attributes(:post_ids => remove_number_from_string(post.id, post_ids))
end
def add_number_to_string(number, string)