# Copy a unique row to another table

**URL:** <https://www.ruby-forum.com/t/copy-a-unique-row-to-another-table/118410>\
**Category:** Rails\
**Created:** [October 26, 2007, 6:06pm UTC](https://www.ruby-forum.com/t/copy-a-unique-row-to-another-table/118410 "2007-10-26T18:06:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![inriz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/50afbb/32.png) [@inriz](https://www.ruby-forum.com/u/inriz)\
**Post date:** [October 26, 2007, 6:06pm UTC](https://www.ruby-forum.com/t/copy-a-unique-row-to-another-table/118410/1 "2007-10-26T18:06:15Z")

</div>

hello list,

ive got a simple problem of copying a row to another table  
the to tables have enough identical columns, so i used the attributes  
hash of my object  
to get less work with it

the my piece of code for that

def activate  
@priv\_property = PrivProperty.find(params[:id])

cols = {}  
@priv\_property.attributes.each do |k, v|  
tmp = {k.intern =\> v}  
cols.merge(tmp)  
tmp.clear  
end

cols[:adat] = Time.now  
cols[:edat] = Time.now  
cols[:sendetermin] = Time.now  
cols[:mkunr] = cols[:maknr]  
cols[:maknr] = 111  
cols[:refnr] = cols[:reccou]  
cols[:rc] = cols[:refnr]  
cols.delete(:reccou)  
cols[:reccou] = nil

[“objstatpriv”, “objreccou”, “objaktiv”, “objdeaktiv”, “objlztage”,  
“vertrag”, “objretage”, “objbrutto”, “objmwst”, “zahlart”, “dtadat”,  
“woher”, “refnr”].each do |c|  
cols.delete©  
end

property = Property.new  
property.save!

ActiveRecord::Base.whiny\_protected\_attributes = false  
property.update\_attributes(cols)  
ActiveRecord::Base.whiny\_protected\_attributes = true

render :nothing =\> true  
end

fetching and so on is ok but the attributes hash has string indexes  
and updates\_attributes calls symbols  
so i decided to solve this by convert the string index to symbol into  
a new hash named cols  
but that doesnt work

and my question is why it doesnt work?

have anybody a good solution or tipp for my problem?

thanks
