Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using gsub to replace String with Symbols in Rails

I have a Rails app that is reading in RSS feeds using the simple_feed gem. However, some of the feeds don't read in correctly - namely, some of the titles have:

`‘`

or

`’`

instead of: "

My titles read in as:

i.title

and I was thinking that gsub can fix this easily, but I was have trouble making it work. I tried:

i.title.gsub(%r[‘]/, '"')

which I'm not even sure would work, but it commented out the line after the #.

Then I tried:

i.title.gsub(%r["‘"]/, '*')

which results in:

C:/Sites/foo/app/views/bar/show.html.erb:20: syntax error, unexpected ','
...( i.title.gsub(%r["‘"]/, '*') )

I haven't really used gsub before, I was trying to work off these examples. Can something please help me figure out what I'm doing wrong?

like image 574
yellowreign Avatar asked Dec 11 '25 08:12

yellowreign


1 Answers

Try with

i.title.gsub("‘", '"')

or with

i.title.gsub(/‘/, '"')
like image 101
rorra Avatar answered Dec 14 '25 03:12

rorra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!