Hi, how can i rewrite this to take out commas in tag field?

def tag_with tags
tags.split(" ").each do |tag|
Tag.find_or_create_by_name(tag).taggables << self
end

i have a text field box where the user can create tags. however, if they
use commas, the comma becomes part of the tag name. how can i prevent
this from happening.

before i call the tag_with, do a remove ‘,’?

thanks

mixplate wrote:

i have a text field box where the user can create tags.
however, if they use commas, the comma becomes
part of the tag name. how can i prevent this from
happening.

before i call the tag_with, do a remove ‘,’?

tags.gsub!(/’,’,’ '/) will substitute a space for a comma.

hth,
Bill

Oops. Should be:

tags.gsub!(/’,’/, ’ ')

----- Original Message -----
From: “Bill W.” [email protected]
To: [email protected]
Sent: Monday, May 28, 2007 1:33 PM
Subject: [Rails] Re: hi, how can i rewrite this to take out commas in
tag
field?

I prefer not to create a table just for tags. I just put a ‘tags’ column
on the table and do this in my view:

@model.tags.split(’,’).compact.collect{|t|
link_to(h(t.strip),"/tags/#{CGI::escape(t.strip)}") }.join(’, ')

test it out on a string

“tag,tagging, , ##@((!~{}|, tagged”.split(’,’).compact.collect{|t|
link_to(h(t.strip),"/tags/#{CGI::escape(t.strip)}") }.join(’, ')

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs