Ruby on Rails Thursday, December 6, 2012

Hello,

If I have a model A as :

name
address
phone

and model B as:

name
address
email

Is it possible to copy a record from A to B with one statement? I am
trying :

@a=A.find(2)
a_attributes=@a.attributes
a_attributes.delete "id"
@b=B.create(a_attributes)

@b.save!

And I am getting an exception :

unknown attribute: phone

How can do this without going through each attribute individually?

Thanks.

--
Posted via http://www.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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment