Hi, i was looking around in the docs, and even though it seems there would be a clean way to do this, i couldn''t find it. i was hoping to take an array of objects, and create a new array of objects, with different id''s. like: user_list = [user1, user2, user3, user4, user5] and then do something in the vicinity of: new_user_list = user_list.collect {|user| User.create(user.attributes)} so that the only differance between the user_list and the new_user_list is the id of each user. for somewhat reason, this isn''t working, as i''m sure there is also a cleaner way to do this. is there? thanks ahead of time, harp -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
harper wrote:> Hi, > > i was looking around in the docs, and even though it seems there would > be a clean way to do this, i couldn''t find it. > i was hoping to take an array of objects, and create a new array of > objects, with different id''s. > > like: > > user_list = [user1, user2, user3, user4, user5] > and then do something in the vicinity of: > > new_user_list = user_list.collect {|user| User.create(user.attributes)} > > so that the only differance between the user_list and the new_user_list > is the id of each user. for somewhat reason, this isn''t working, as i''m > sure there is also a cleaner way to do this. > is there? > > thanks ahead of time, > > harpHey Harp, I have not tried this out yet, but the map method is handy for this sort of thing. something like: new_user_list = user_list.map do {|user| User.create(user.attributes)} That should work. -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Phil Peterman wrote:> harper wrote: >> Hi, >> >> i was looking around in the docs, and even though it seems there would >> be a clean way to do this, i couldn''t find it. >> i was hoping to take an array of objects, and create a new array of >> objects, with different id''s. >> >> like: >> >> user_list = [user1, user2, user3, user4, user5] >> and then do something in the vicinity of: >> >> new_user_list = user_list.collect {|user| User.create(user.attributes)} >> >> so that the only differance between the user_list and the new_user_list >> is the id of each user. for somewhat reason, this isn''t working, as i''m >> sure there is also a cleaner way to do this. >> is there? >> >> thanks ahead of time, >> >> harp > > Hey Harp, > > I have not tried this out yet, but the map method is handy for this sort > of thing. > > something like: > > new_user_list = user_list.map do {|user| User.create(user.attributes)} > > That should work....ok, after trying a little after writing this post, the problem turns out to be becuase of a file column issue - - not the create/attribute method. for somewhat reason, the create method does not accept a file_column attribute (needs multipart enctype). to somehow escape this, i was wondering whether this could be done simply by an sql snippit or something... -- Posted via ruby-forum.com. --~--~---------~--~----~------------~-------~--~----~ 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 groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---