Created
August 5, 2010 16:10
-
-
Save ledermann/509954 to your computer and use it in GitHub Desktop.
Monkey patch for the Rails plugin "acts_as_taggable_on" to handle dirty tracking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Monkey patch for the Rails plugin "acts_as_taggable_on" to handle dirty tracking | |
# http://github.com/mbleigh/acts-as-taggable-on/issues#issue/1 | |
module ActsAsTaggableOn::Taggable | |
module Core | |
module InstanceMethods | |
def set_tag_list_on_with_dirty_tracking(context,new_list) | |
value = new_list.to_s | |
attr = "#{context.to_s.singularize}_list" | |
if changed_attributes.include?(attr) | |
# The attribute already has an unsaved change. | |
old = changed_attributes[attr] | |
changed_attributes.delete(attr) if (old == value) | |
else | |
old = tag_list_on(context).to_s | |
changed_attributes[attr] = old if (old != value) | |
end | |
set_tag_list_on_without_dirty_tracking(context,new_list) | |
end | |
alias_method_chain :set_tag_list_on, :dirty_tracking | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is a typo:
value = new_list.is_a?(Array) ? new_list.join(', ') : value
But correct is:
value = new_list.is_a?(Array) ? new_list.join(', ') : new_list
Thanks for sharing it!