rss
twitter
    Find out what I'm doing, Follow Me :)

Adding Tags without spaces

Some times it is needed to addd the tag using acts_as_taggable plugin that you don't need spaces while creating tags. Means the tags are seprated not by spaces but with commas(,). For the we have to modify the code in the acts_as_taggable plugin.

Just open the file \vendor\plugins\acts_as_taggable\lib\tag.rb

We have to midify the method self.parse(list)

with the following code:

def self.parse(list)
unless list.kind_of? Array
tag_names = []

# first, pull out the quoted tags
list.gsub!(/"(.*?)"s*/ ) { tag_names << $1; "" }

# then, replace all commas with a space
list.gsub!(/,/, " ")

# then, get whatever's left
tag_names.concat list.split(/s/)

# strip whitespace from the names
tag_names = tag_names.map { |t| t.strip }

# delete any blank tag names
tag_names = tag_names.delete_if { |t| t.empty? }

return tag_names
else
tag_names = list.collect {|tag| tag.nil? ? nil : tag.to_s}
return tag_names.compact
end
end

0 comments: