I have a User model and users table. A user can have many phone numbers so I have a separate Model named Phone
.
I am using this association for that:
Model
User
attr_accessible :id, :name, :screenname,:fullname,:phones_attributes
has_many :phones,:dependent => :destroy
Phone
attr_accessible :phone
belongs to :users
Above code works fine.
Admin want to copy any user's record into user_temp
and phone_temp
table as well (I have separate models named UserTemp and PhoneTemp).
How can I do this?
The simplest way would be:
phone_item = Phone.find(x) # Get the phone item you want to copy
# you may have obtained this some other way
PhoneTemp.create(phone_item.attributes) if phone_item
Similarly for the User.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With