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):
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=
order.rb (this table has two columns: ticket_id and part_id)
If this table really has only those two columns a simple
has_and_belongs_to_many relation would be the appropriate way.
@T.N.T. True, it could, but once I get the basic functionality I’m going
to add additional attributes, such as quantity.
In the Railscasts about nested forms, rbates shows you how to do
something similar but it creates new items. For example, create new
Survey, and create new questions along with the new survey.
What I need is, new Ticket, attach existing Parts (selected from a drop
down menu) to the ticket using the Orders table (ticket_id, part_id)