# Save using Update

**URL:** <https://www.ruby-forum.com/t/save-using-update/50946>\
**Category:** Rails\
**Created:** [December 23, 2005, 1:04am UTC](https://www.ruby-forum.com/t/save-using-update/50946 "2005-12-23T01:04:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![r00by\_n00by](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/839c29/32.png) [@r00by\_n00by](https://www.ruby-forum.com/u/r00by_n00by)\
**Post date:** [December 23, 2005, 1:04am UTC](https://www.ruby-forum.com/t/save-using-update/50946/1 "2005-12-23T01:04:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![r00by\_n00by](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/839c29/32.png) [@r00by\_n00by](https://www.ruby-forum.com/u/r00by_n00by)\
**Post date:** [December 23, 2005, 1:40am UTC](https://www.ruby-forum.com/t/save-using-update/50946/2 "2005-12-23T01:40:12Z")

</div>

On 12/22/05, r00by n00by [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![r00by\_n00by](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/839c29/32.png) [@r00by\_n00by](https://www.ruby-forum.com/u/r00by_n00by)\
**Post date:** [December 23, 2005, 1:41am UTC](https://www.ruby-forum.com/t/save-using-update/50946/3 "2005-12-23T01:41:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![r00by\_n00by](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/839c29/32.png) [@r00by\_n00by](https://www.ruby-forum.com/u/r00by_n00by)\
**Post date:** [December 23, 2005, 2:46am UTC](https://www.ruby-forum.com/t/save-using-update/50946/4 "2005-12-23T02:46:24Z")

</div>

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](http://aflax.org) , which is kind of a Javascript-Flash bridge.

regards

---

<div class="post-metadata">

**Author:** ![r00by\_n00by](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/839c29/32.png) [@r00by\_n00by](https://www.ruby-forum.com/u/r00by_n00by)\
**Post date:** [December 24, 2005, 5:44pm UTC](https://www.ruby-forum.com/t/save-using-update/50946/5 "2005-12-24T17:44:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![r00by\_n00by](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/839c29/32.png) [@r00by\_n00by](https://www.ruby-forum.com/u/r00by_n00by)\
**Post date:** [December 23, 2005, 1:55am UTC](https://www.ruby-forum.com/t/save-using-update/50946/6 "2005-12-23T01:55:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![r00by\_n00by](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/839c29/32.png) [@r00by\_n00by](https://www.ruby-forum.com/u/r00by_n00by)\
**Post date:** [December 30, 2005, 4:26am UTC](https://www.ruby-forum.com/t/save-using-update/50946/7 "2005-12-30T04:26:54Z")

</div>

On 12/24/05, r00by n00by [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](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](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](http://www.cnn.com)”, “id”=\>5}\>
