fix metatags not updating favgroup post count
This commit is contained in:
@@ -42,12 +42,9 @@ class FavoriteGroupsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
# need to do this in order for synchronize! to work correctly
|
|
||||||
@favorite_group = FavoriteGroup.find(params[:id])
|
@favorite_group = FavoriteGroup.find(params[:id])
|
||||||
check_privilege(@favorite_group)
|
check_privilege(@favorite_group)
|
||||||
@favorite_group.attributes = params[:favorite_group]
|
@favorite_group.update_attributes(params[:favorite_group])
|
||||||
@favorite_group.synchronize
|
|
||||||
@favorite_group.save
|
|
||||||
unless @favorite_group.errors.any?
|
unless @favorite_group.errors.any?
|
||||||
flash[:notice] = "Favorite group updated"
|
flash[:notice] = "Favorite group updated"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class FavoriteGroup < ActiveRecord::Base
|
|||||||
before_validation :strip_name
|
before_validation :strip_name
|
||||||
validate :creator_can_create_favorite_groups, :on => :create
|
validate :creator_can_create_favorite_groups, :on => :create
|
||||||
validate :validate_number_of_posts
|
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]
|
attr_accessible :name, :post_ids, :post_id_array, :as => [:member, :gold, :platinum, :builder, :contributor, :janitor, :moderator, :admin, :default]
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
@@ -149,32 +149,24 @@ class FavoriteGroup < ActiveRecord::Base
|
|||||||
@post_id_array_was = nil
|
@post_id_array_was = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def synchronize
|
def update_post_count
|
||||||
added = post_id_array - post_id_array_was
|
|
||||||
removed = post_id_array_was - post_id_array
|
|
||||||
|
|
||||||
normalize_post_ids
|
normalize_post_ids
|
||||||
clear_post_id_array
|
clear_post_id_array
|
||||||
self.post_count = post_id_array.size
|
self.post_count = post_id_array.size
|
||||||
end
|
end
|
||||||
|
|
||||||
def synchronize!
|
|
||||||
synchronize
|
|
||||||
save
|
|
||||||
end
|
|
||||||
|
|
||||||
def add!(post)
|
def add!(post)
|
||||||
return if contains?(post.id)
|
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
|
clear_post_id_array
|
||||||
|
update_attributes(:post_ids => add_number_to_string(post.id, post_ids))
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove!(post)
|
def remove!(post)
|
||||||
return unless contains?(post.id)
|
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
|
clear_post_id_array
|
||||||
|
update_attributes(:post_ids => remove_number_from_string(post.id, post_ids))
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_number_to_string(number, string)
|
def add_number_to_string(number, string)
|
||||||
|
|||||||
Reference in New Issue
Block a user