Im using Rails 3.0.3
I have a Model Bill:
class Bill < ActiveRecord::Base
has_many :entries
accepts_nested_attributes_for :entries
end
In my Bill view i am using nested forms to create new entries in bills and with Javascript i insert existing entries with at this point, have no bill_id:
$("#row" + nested_form_id).append("<input type='hidden' name='bill[entries_attributes][" + nested_form_id + "][id]' id='bill_entries_attributes_" + nested_form_id + "_id' value='" + id +"' >");
when i submit the form i get this error:
ActiveRecord::RecordNotFound (Couldn't find Entry with ID=127 for Bill with ID=):
app/controllers/bills_controller.rb:121:in `new'
app/controllers/bills_controller.rb:121:in `create'
so the problem is, that rails is looking for the entry in bills when i submit
any idea how i can fix this?
I couldnt figure out how this is possible with nested forms, so i set the entries which allready exists manually to the bill: