why I can't update data, but I can insert data into new mode

Discussion in 'Ruby' started by OnRails Ruby, Oct 19, 2007.

  1. OnRails Ruby

    OnRails Ruby Guest

    why I can't update data, but I can insert data into new model.
    like this:
    if File.find_by_id(id)
    file=File.find_by_id(id)
    else
    file=File.new

    file.name=name
    file.save

    there is a problem, when there don't find id, there is no problem, But
    when find id, update the field,
    there is Error, there said: undefined method 'name='
    why? who can help me? Thanks!!
    --
    Posted via http://www.ruby-forum.com/.
     
    OnRails Ruby, Oct 19, 2007
    #1
    1. Advertising

  2. OnRails Ruby

    bbiker Guest

    On Oct 19, 4:40 pm, OnRails Ruby <> wrote:
    > why I can't update data, but I can insert data into new model.
    > like this:
    > if File.find_by_id(id)
    > file=File.find_by_id(id)
    > else
    > file=File.new
    >
    > file.name=name
    > file.save
    >
    > there is a problem, when there don't find id, there is no problem, But
    > when find id, update the field,
    > there is Error, there said: undefined method 'name='
    > why? who can help me? Thanks!!
    > --
    > Posted viahttp://www.ruby-forum.com/.


    you did not define 'name'

    file.name = "name"
    file.save

    not tested
     
    bbiker, Oct 20, 2007
    #2
    1. Advertising

  3. OnRails Ruby

    bbiker Guest

    On Oct 19, 4:40 pm, OnRails Ruby <> wrote:
    > why I can't update data, but I can insert data into new model.
    > like this:
    > if File.find_by_id(id)
    > file=File.find_by_id(id)
    > else
    > file=File.new
    >
    > file.name=name
    > file.save
    >
    > there is a problem, when there don't find id, there is no problem, But
    > when find id, update the field,
    > there is Error, there said: undefined method 'name='
    > why? who can help me? Thanks!!
    > --
    > Posted viahttp://www.ruby-forum.com/.


    OOPS!!! my bad

    there is no name method for name=

    there is a rename method

    File.rename("old_file_name", "new_file_name")
     
    bbiker, Oct 20, 2007
    #3
    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. John J Lee
    Replies:
    3
    Views:
    489
    bruno at modulix
    Dec 1, 2005
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,995
    Smokey Grindel
    Dec 2, 2006
  3. Edward Loper
    Replies:
    0
    Views:
    473
    Edward Loper
    Aug 7, 2007
  4. John J Lee
    Replies:
    0
    Views:
    527
    John J Lee
    Aug 7, 2007
  5. jobs at webdos
    Replies:
    0
    Views:
    477
    jobs at webdos
    Oct 9, 2006
Loading...

Share This Page