mixplate
2007-May-28 17:30 UTC
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bill Walton
2007-May-28 18:33 UTC
Re: hi, how can i rewrite this to take out commas in tag field?
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bill Walton
2007-May-28 18:42 UTC
Re: hi, how can i rewrite this to take out commas in tag field?
Oops. Should be: tags.gsub!(/'',''/, '' '') ----- Original Message ----- From: "Bill Walton" <bill.walton-xwVYE8SWAR3R7s880joybQ@public.gmane.org> To: <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Sent: Monday, May 28, 2007 1:33 PM Subject: [Rails] Re: hi, how can i rewrite this to take out commas in tag field?> > 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 > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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('', '') -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---