I have a form which creates a Listing - but I want it to create some associated records. My models are structured as follows:
- Listing
has_and_belongs_to_manyCards (as in business cards) - Card
belongs_toCompany (a company can have many business cards)
When I submit this form I want to create a Listing, a Card and a Company in one shot. Also validations should be run.
Now I understand that if I want to include a Card field in my Listing form I'll use something like:
@card = @listing.cards.build
[...]
fields_for(@listing, @card) do |c|
But what should I do if I want to include Company fields in the form? I checked, but @card.company is nil.