string

S

Shai Rosenfeld

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
 
P

Phrogz

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

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top