I've been tracking the SO site as my rails progress has developed and it is a good source of information.
I am writing an application to maintain a bunch of hosts and their associated warranty.
contracts
A host can have many contracts and a contract can apply to many hosts.
So I have three classes: Host
, WarrantyContract
and HostWarranty
.
The HostWarranty
model has FK references to the host and WarrantyContract
as well as a comments field.
What I need to be able to do is manage the contents of the host_warranties
table (assetid, warranty_contract, comments) through the host and warranty_contract
pages, so that when editing a host's details, I can apply one or more contracts; when I edit a contract I can indicate what host(s) it applies to.
I have been exploring using has_many
, accepts_nested_attributes_for
and has_and_belongs_to_many
(Many-to-many relationship with the same model in rails? being the main source so far) but I am struggling with how I develop the view _form
template; most examples I have seen utilise the fields_for
method, whereas what I need is a <select>
list of names and id's.
I'm particularly after suggested solutionsm but more an idea of what kind of api areas I should be looking at or googling for.