The default delimiter in the acts-as-taggable-on gem is a comma. I'd like to change this to a space throughout my Rails 3 application. For example, tag_list should be assigned like this:
object.tag_list = "tagone tagtwo tagthree"
rather than like this:
object.tag_list = "tagone, tagtwo, tagthree"
What is the best way to go about changing the delimiter?
You need define the delimiter class variable in ActsAsTaggableOn::TagList class
In an initializer add that :
ActsAsTaggableOn::TagList.delimiter = ' '
I wouldn't go hacking around inside acts-as-taggable-on, just create another method on the class that implements it:
class MyClass < ActiveRecord::Base
acts_as_taggable
def human_tag_list
self.tag_list.gsub(', ', ' ')
end
def human_tag_list= list_of_tags
self.tag_list = list_of_tags.gsub(' ', ',')
end
end
MyClass.get(1).tag_list # => "tagone, tagtwo, tagthree"
MyClass.get(1).human_tag_list # => "tagone and tagtwo and tagthree"
MyClass.get(1).human_tag_list = "tagone tagtwo tagthree"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With