I have 3 models: ticket, part, order
ticket.rb has_many :orders has_many :parts, :through => :orders accepts_nested_attributes_for :orders accepts_nested_attributes_for :parts
part.rb has_many :orders has_many :tickets, :through => :orders
order.rb (this table has two columns: ticket_id and part_id) belongs_to :part belongs_to :ticket
Each support ticket might have "parts" attached to it. Let's say a PC technician received a support ticket to replace a hard-drive, the app should be able to add a "part" to the ticket. So I have two drop down menus for parts.
So in my view, the _form.html.erb file for the ticket, I have this (which displays two drop down menus for parts): <div class="field"> <%= f.label :solution %><br /> <%= f.text_area :solution, :rows => 3 %> </div>
<div class="field"> <% f.fields_for :orders do |o| %> <p> <%= o.label :part_id, "Part" %><br /> <%= o.collection_select :id, @parts, :id, :name, :prompt => "Select" %> </p> <% end %> </div>
in tickets_controller.rb I have this (which allows me to display two drop down menus for parts): def new @ticket = Ticket.new 2.times { @ticket.orders.build } end
But when I submit the form, I get this error: Couldn't find Order with ID=1 for Ticket with ID=