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.
Fresh M. (Guest)
on 2009-03-06 11: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
Franz S. (Guest)
on 2009-03-06 11:50
(Received via mailing list)
On Fri, Mar 6, 2009 at 10:35 AM, Fresh M.
<removed_email_address@domain.invalid> 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.