Ruby on Rails
Thursday, December 6, 2012
On Fri, Dec 7, 2012 at 9:30 AM, renu mehta <lists@ruby-forum.com> wrote:
Hello,
If I have a model A as :
name
address
phone
and model B as:
name
address
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?
use slice.
B.create a.attributes.slice(:name, :address, :email)
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.
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment