Creating duplicate object#Base

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

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.

Phil P. 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…