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