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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2 Jul 2008, at 16:10, MalHayn wrote:> > 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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 2, 2008, at 12:19 PM, Frederick Cheung wrote:> On 2 Jul 2008, at 16:10, MalHayn wrote: >> 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 > > FredYou 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 Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---