Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move loading tags for saving to method #371

Merged
merged 1 commit into from
Dec 11, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
Original file line number Diff line number Diff line change
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