string

Discussion in 'Ruby' started by Shai Rosenfeld, Aug 26, 2007.

  1. 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/.
    Shai Rosenfeld, Aug 26, 2007
    #1
    1. Advertising

  2. Shai Rosenfeld

    Phrogz Guest

    On Aug 26, 4:07 am, Shai Rosenfeld <> 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
    }
    Phrogz, Aug 26, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mladen Adamovic
    Replies:
    0
    Views:
    723
    Mladen Adamovic
    Dec 4, 2003
  2. Mladen Adamovic
    Replies:
    3
    Views:
    14,559
    Mladen Adamovic
    Dec 5, 2003
  3. Matt
    Replies:
    3
    Views:
    479
    Tor Iver Wilhelmsen
    Sep 17, 2004
  4. Bruce Sam
    Replies:
    15
    Views:
    7,869
    John C. Bollinger
    Nov 19, 2004
  5. =?Utf-8?B?UmFqZXNoIHNvbmk=?=

    'System.String[]' from its string representation 'String[] Array'

    =?Utf-8?B?UmFqZXNoIHNvbmk=?=, May 4, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,786
    =?Utf-8?B?UmFqZXNoIHNvbmk=?=
    May 4, 2006
Loading...

Share This Page