Skip to content

Instantly share code, notes, and snippets.

@bouchard
Created December 28, 2011 17:18
Show Gist options
  • Select an option

  • Save bouchard/1528761 to your computer and use it in GitHub Desktop.

Select an option

Save bouchard/1528761 to your computer and use it in GitHub Desktop.
Force Lowercase and Force Parameterize for Acts as Taggable On.
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
@visoft
Copy link
Copy Markdown

visoft commented Jan 30, 2012

Thanks for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment