Friday, March 27, 2009

Duplicating Activerecord record

Was trying to copy an existing DB record by using
 
parent_record = User.find(1)

new_user = User.new(parent_record)

new_user.name = 'new_name'

new_user.save

But this ended in throwing stringify_keys error for User

This can done by specifying

 
new_user = User.new(parent_record.attributes)


Hope this helps!

No comments: