I have a string of state codes (ie ''MD,PA,VA,WV'') i''m passing from a select list (:allow_multiple => true), in which I''m trying to replace the commas with "'',''". I have the following gsub, which works fine in irb, however in Rails it''s returning "'''',''''" (double single-quotes). states = params[:states].gsub(/,/, "'',''") Any suggestions? -- Posted via http://www.ruby-forum.com/.
Brian Penrose wrote:> I have a string of state codes (ie ''MD,PA,VA,WV'') i''m passing from a > select list (:allow_multiple => true), in which I''m trying to replace > the commas with "'',''". I have the following gsub, which works fine in > irb, however in Rails it''s returning "'''',''''" (double single-quotes). > > states = params[:states].gsub(/,/, "'',''") > > Any suggestions?Your gsub statement looks fine, but my guess is that it''s somehow getting called twice, which is why you''re getting the quotes doubled. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
Marnen Laibow-Koser wrote:> Brian Penrose wrote: >> I have a string of state codes (ie ''MD,PA,VA,WV'') i''m passing from a >> select list (:allow_multiple => true), in which I''m trying to replace >> the commas with "'',''". I have the following gsub, which works fine in >> irb, however in Rails it''s returning "'''',''''" (double single-quotes). >> >> states = params[:states].gsub(/,/, "'',''") >> >> Any suggestions? > > Your gsub statement looks fine, but my guess is that it''s somehow > getting called twice, which is why you''re getting the quotes doubled. > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.orgThanks Maren...I''ll look into it...but, the very next line in my code passes the value of states into a find, so not sure what would cause it to be called again. -- Posted via http://www.ruby-forum.com/.
2009/7/20 Brian Penrose <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Marnen Laibow-Koser wrote: >> Brian Penrose wrote: >>> I have a string of state codes (ie ''MD,PA,VA,WV'') i''m passing from a >>> select list (:allow_multiple => true), in which I''m trying to replace >>> the commas with "'',''". I have the following gsub, which works fine in >>> irb, however in Rails it''s returning "'''',''''" (double single-quotes). >>> >>> states = params[:states].gsub(/,/, "'',''") >>> >>> Any suggestions? >> >> Your gsub statement looks fine, but my guess is that it''s somehow >> getting called twice, which is why you''re getting the quotes doubled. >> >> Best, >> -- >> Marnen Laibow-Koser >> http://www.marnen.org >> marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > Thanks Maren...I''ll look into it...but, the very next line in my code > passes the value of states into a find, so not sure what would cause it > to be called again. > --In this sort of situation I would use ruby-debug to break into the code at that point, then you can examine the data in and out of gsub and possibly get a clue as to what is happening. Colin