Forum: Ruby on Rails Replace

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.
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-03-06 10:35
What is the easiest way to replace record in database?

Better that this:

@old = Order.find(5)
@new = Order.find(90)

@old.x = @new.x
@old.y = @new.y
@old.z = @new.z
@old.w = @new.w
@old.p = @new.p
@old.r = @new.r
...

@old.save


So now @old = @new except @old.id and @old.created_at
9b8d00f99fe595bdc45fd30439cf9c8f?d=identicon&s=25 Franz Strebel (Guest)
on 2009-03-06 10:50
(Received via mailing list)
On Fri, Mar 6, 2009 at 10:35 AM, Fresh Mix
<rails-mailing-list@andreas-s.net> wrote:
>
> What is the easiest way to replace record in database?
>
> Better that this:
>
> @old = Order.find(5)
> @new = Order.find(90)
>
> @old.x = @new.x
> @old.y = @new.y

@old.attributes = @new.attributes

or you can even get rid of @new completely

@old.attributes = Order.find(90).attributes

@old.save
This topic is locked and can not be replied to.