# String

**URL:** <https://www.ruby-forum.com/t/string/113025>\
**Category:** Ruby\
**Created:** [August 26, 2007, 12:07pm UTC](https://www.ruby-forum.com/t/string/113025 "2007-08-26T12:07:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![harper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@harper](https://www.ruby-forum.com/u/harper)\
**Post date:** [August 26, 2007, 12:07pm UTC](https://www.ruby-forum.com/t/string/113025/1 "2007-08-26T12:07:35Z")

</div>

this may be a slightly unrelated question, but i was hoping someone had  
some small quick answer for me … does anyone know how to modify /  
change existing text in a db?

with the code

@foods = Food.find(:all)  
food\_rows = @foods.collect(&:fruit)  
food\_rows.each |r|  
r.gsub(“really”, “”)  
end

i get a good end result (if the data was

Food.find(1).fruit = “we really need apples”  
Food.find(2).fruit = “we really need kiwis”  
Food.find(3).fruit = “we really need oranges”

that is, after the code, i get

“we need apples”  
“we need kiwis”  
“we need oranges”

which is good, but that is the program’s output. i was wondering whether  
someone knew a way to do this, that modifies the data in the database  
(mysql).

thanks for the hassle

---

<div class="post-metadata">

**Author:** ![harper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@harper](https://www.ruby-forum.com/u/harper)\
**Post date:** [August 26, 2007, 4:25pm UTC](https://www.ruby-forum.com/t/string/113025/2 "2007-08-26T16:25:52Z")

</div>

On Aug 26, 4:07 am, Shai R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end  
> You need to .save the individual Food records. Something like  
> (untested):

Food.find(:all).each{ |food|  
food.fruit = food.fruit.gsub( “really”, “” )  
food.save  
}
