Skip to content

Commit

Permalink
Small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tomeric committed Feb 7, 2010
1 parent b298316 commit 42b51e3
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/acts_as_taggable_on/acts_as_taggable_on.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,19 +392,18 @@ def save_cached_tag_list
def save_tags
contexts = custom_contexts + self.class.tag_types.map(&:to_s)

# raise contexts.map { |context| tag_list_cache_on(context) }.inspect if $debug

transaction do
contexts.each do |context|
cache = tag_list_cache_on(context)

cache.each do |owner, list|
new_tags = Tag.find_or_create_all_with_like_by_name(list.uniq)
taggings = Tagging.find(:all, :conditions => { :taggable_id => self.id, :taggable_type => self.class.to_s })

# Destroy old taggings:
if owner
old_tags = tags_on(context, owner) - new_tags
old_taggings = taggings.find(:all, :conditions => { :tag_id => old_tags, :tagger_id => owner, :tagger_type => owner.class.to_s, :context => context })
old_taggings = Tagging.find(:all, :conditions => { :taggable_id => self.id, :taggable_type => self.class.to_s, :tag_id => old_tags, :tagger_id => owner, :tagger_type => owner.class.to_s, :context => context })

old_taggings.each(&:destroy)
else
Expand All @@ -418,7 +417,7 @@ def save_tags

# create new taggings:
new_tags.each do |tag|
taggings.create!(:tag_id => tag.id, :context => context, :tagger => owner)
Tagging.create!(:tag_id => tag.id, :context => context, :tagger => owner, :taggable => self)
end
end
end
Expand Down

3 comments on commit 42b51e3

@ledermann
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not work with STI, please see #37

@espen
Copy link

@espen espen commented on 42b51e3 Feb 23, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also have this problem with STI. Had to revert back to 1.1.1. How can I apply the patch? I tried 'sudo patch -p2 < sti.patch' in the acts-as-taggable gem directory, but was asked which files to patch and it did not work.

@ledermann
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have commited the patch into my fork: a2c56a0dde1de5c8ca899a139322dda2255e9c5f

Please sign in to comment.