Copying variables between rows

Is there an elegant way of copying some variables from one row to
another row?

Here is the current code:

color = Color.find(id, :select => “a, b, c, d, e, f”)
copy = Color.find(copy, :select => “c, d, e”)

color.c = copy.c
color.d = copy.d
color.e = copy.e

color.update

On 2 Jul 2008, at 16:10, MalHayn wrote:

color.d = copy.d
color.e = copy.e

don’t know if it’s a good idea but
color.attributes = copy.attributes
would probably do the trick

Fred

On Jul 2, 2008, at 12:19 PM, Frederick C. wrote:

color.d = copy.d
color.e = copy.e

don’t know if it’s a good idea but
color.attributes = copy.attributes
would probably do the trick

Fred

You probably need to be aware that using :select causes the Color
objects to be marked readonly and cannot be saved. Add
a :readonly=>false if you want to save the Color object again.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Thanks Fred,

color.attributes = copy.attributes did the trick.

Your help has saved hundreds of lines of code.

Previously I tried .clone, .dub, .reject, .to_hsh, .hash, and more.
I knew there was a very simple answer.

Thanks Rob,

That is a good point.
In the working code “select” is not used on color, only copy.

Mark