Skip to content

Commit

Permalink
Merge pull request #371 from makaroni4/master
Browse files Browse the repository at this point in the history
Move loading tags for saving to method
  • Loading branch information
bf4 committed Dec 11, 2013
2 parents c3b4e24 + 691f489 commit 8f7a830
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
Expand Up @@ -329,14 +329,20 @@ def reload(*args)
super(*args)
end

##
# Find existing tags or create non-existing tags
def load_tags(tag_list)
ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name(tag_list)
end

def save_tags
tagging_contexts.each do |context|
next unless tag_list_cache_set_on(context)
# List of currently assigned tag names
tag_list = tag_list_cache_on(context).uniq

# Find existing tags or create non-existing tags:
tags = ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name(tag_list)
tags = load_tags(tag_list)

# Tag objects for currently assigned tags
current_tags = tags_on(context)
Expand All @@ -355,7 +361,7 @@ def save_tags
new_tags |= current_tags[index...current_tags.size] & shared_tags

# Order the array of tag objects to match the tag list
new_tags = tags.map do |t|
new_tags = tags.map do |t|
new_tags.find { |n| n.name.downcase == t.name.downcase }
end.compact
end
Expand Down

0 comments on commit 8f7a830

Please sign in to comment.