Created
December 28, 2011 17:18
-
-
Save bouchard/1528761 to your computer and use it in GitHub Desktop.
Force Lowercase and Force Parameterize for Acts as Taggable On.
This file contains 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
module ActsAsTaggableOn | |
class TagList < Array | |
cattr_accessor :force_lowercase, :force_parameterize | |
self.force_lowercase = false | |
self.force_parameterize = false | |
private | |
# Remove whitespace, duplicates, and blanks. | |
def clean! | |
reject! { |name| name.blank? } | |
map! { |name| name.strip } | |
map! { |name| name.downcase } if force_lowercase | |
map! { |name| name.parameterize } if force_parameterize | |
map! { |name| name.gsub('_','-') } | |
uniq! | |
end | |
end | |
end | |
# Set Tag List options. | |
ActsAsTaggableOn::TagList.delimiter = ',' | |
ActsAsTaggableOn::TagList.force_lowercase = true | |
ActsAsTaggableOn::TagList.force_parameterize = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this.