Hi,

How would I go about creating a new object with an existing nested
attribute?

class Item < ActiveRecord::Base
  has_and_belongs_to_many :attachments
  accepts_nested_attributes_for :attachments, :allow_destroy => true
end

i = Item.new
=> #<Item id: nil, name: nil ... >

params = { :attachments_attributes => { "0" => {:id =>
Attachment.find(:last).id.to_s}} }
=> {:attachments_attributes=>{"0"=>{:id=>"62"}}}

i.update_attributes(params)
ActiveRecord::RecordNotFound: Couldn't find Attachment with ID=62 for
Item with ID=

I've tried using Google to find a solution, but to no avail.

Would be very grateful for any advice.

Jim

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to