Forum: Ruby on Rails Save using Update

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ddb3433423c9863f21f888fee1400d85?d=identicon&s=25 r00by n00by (Guest)
on 2005-12-23 01:04
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?
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2005-12-23 01:40
(Received via mailing list)
On 12/22/05, r00by n00by <uakpxmgxswozo@mailinator.com> 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
137039860fa6b38713e1349da8a4137d?d=identicon&s=25 Marc Love (Guest)
on 2005-12-23 01:41
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
09b87770d7b50f3a7f913984477eea23?d=identicon&s=25 speechexpert (Guest)
on 2005-12-23 01:55
(Received via mailing list)
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
30269682335f1fb247d71969fa715b5e?d=identicon&s=25 Roberto Saccon (rsaccon)
on 2005-12-23 02:46
(Received via mailing list)
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
Fbe5133e8ac4c60ce140e07851779f30?d=identicon&s=25 r00by n00by (Guest)
on 2005-12-24 17:44
Marc Love 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?
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2005-12-30 04:26
(Received via mailing list)
On 12/24/05, r00by n00by <0539y2fupguaui80@jetable.com> 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}>
This topic is locked and can not be replied to.