MalHayn
(MalHayn)
1
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
don't know if it's a good idea but
color.attributes = copy.attributes
would probably do the trick
Fred
rab
(Rob Biedenharn)
3
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
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
-Rob
Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
MalHayn
(MalHayn)
4
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