Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > string

Reply
Thread Tools

string

 
 
Shai Rosenfeld
Guest
Posts: n/a
 
      08-26-2007
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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Phrogz
Guest
Posts: n/a
 
      08-26-2007
On Aug 26, 4:07 am, Shai Rosenfeld <(E-Mail Removed)> wrote:
> 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
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'System.String[]' from its string representation 'String[] Array' =?Utf-8?B?UmFqZXNoIHNvbmk=?= ASP .Net 0 05-04-2006 04:29 PM
Is "String s = "abc";" equal to "String s = new String("abc");"? Bruce Sam Java 15 11-19-2004 06:03 PM
String[] files = {"a.doc, b.doc"}; VERSUS String[] files = new String[] {"a.doc, b.doc"}; Matt Java 3 09-17-2004 10:28 PM
String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 3 12-05-2003 04:20 PM
Re: String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 0 12-04-2003 04:40 PM



Advertisments