From 3cc7dbbedc10397a3b3f053bcc1b05ed5a4e3135 Mon Sep 17 00:00:00 2001 From: Toks Date: Mon, 29 Jun 2015 15:46:29 -0400 Subject: [PATCH] fix metatags not updating favgroup post count --- app/controllers/favorite_groups_controller.rb | 5 +---- app/models/favorite_group.rb | 16 ++++------------ 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/app/controllers/favorite_groups_controller.rb b/app/controllers/favorite_groups_controller.rb index 4a5a1799f..b778ea562 100644 --- a/app/controllers/favorite_groups_controller.rb +++ b/app/controllers/favorite_groups_controller.rb @@ -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 diff --git a/app/models/favorite_group.rb b/app/models/favorite_group.rb index 1d83ab79f..c1e0425a0 100644 --- a/app/models/favorite_group.rb +++ b/app/models/favorite_group.rb @@ -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)