Save using Update

Hi,

I want to update an existing row in table “items” where items.id == 10
I tried this:

item = Item.new
item.f1 = …
item.f2 = …

item.id = 10
item.save

I got an error
Duplicate entry … for key 10 : INSERT INTO items …

How do I make item.save to use UPDATE instead of INSERT?

On 12/22/05, r00by n00by [email protected] wrote:

item.save

I got an error
Duplicate entry … for key 10 : INSERT INTO items …

How do I make item.save to use UPDATE instead of INSERT?

item = Item.find 10
item.f1 = …
item.f2 = …
item.save

Joe

r00by n00by wrote:

Hi,

I want to update an existing row in table “items” where items.id == 10
I tried this:

item = Item.new
item.f1 = …
item.f2 = …

item.id = 10
item.save

I got an error
Duplicate entry … for key 10 : INSERT INTO items …

How do I make item.save to use UPDATE instead of INSERT?

item = Item.find(10)
item.f1 = …
item.f2 = …

item.save

the easiest is to use the flashplayer (wich is on 98% of all computers),
whichi s abel to record and playback audio. At the backend you need a
flash
communication server for receiving the upstreamed recordings. To create
and
control dynmaically flash-movies from within a rails app, I would take a
look at http://aflax.org , which is kind of a Javascript-Flash bridge.

regards

Marc L. wrote:

r00by n00by wrote:

Hi,

I want to update an existing row in table “items” where items.id == 10
I tried this:

item = Item.new
item.f1 = …
item.f2 = …

item.id = 10
item.save

I got an error
Duplicate entry … for key 10 : INSERT INTO items …

How do I make item.save to use UPDATE instead of INSERT?

item = Item.find(10)
item.f1 = …
item.f2 = …

item.save

Sometimes the value of item is already given (not from the database), so
I need to do something like this:

item10 = Item.find(10)
item10 = item.clone
item10.save

but this dosn’t work. What’s the right way to do it?

I am looking for a program I can put into a web page for recording and
playback of audio files.
It is assumed that the client machne has sound card, microphone, etc.
It is OK to restrict to IE if necessary.
Anyone tackle this one?
Thanks in advance,
John B

On 12/24/05, r00by n00by [email protected] wrote:


item.f2 = …
item10.save

but this dosn’t work. What’s the right way to do it?

Maybe use dclone?

original = Role.find :first
=> #<Role:0x2aaaac65d830 @attributes={“name”=>“Community / Local
Village Director”, “training_link”=>“http://www.cnn.com”, “id”=>“1”}>

new_one = original.dclone
=> #<Role:0x2aaaac65a2c0 @new_record=true,
@attributes={“name”=>“Community / Local Village Director”,
“training_link”=>“http://www.cnn.com”}>

new_one.save
=> true

new_one
=> #<Role:0x2aaaac65a2c0 @errors=#<ActiveRecord::Errors:0x2aaaac653178
@errors={}, @base=#<Role:0x2aaaac65a2c0 …>>, @new_record=false,
@new_record_before_save=false, @attributes={“name”=>“Community / Local
Village Director”, “training_link”=>“http://www.cnn.com”, “id”=>5}>