I am new to Ruby, so apologies.
I’m attempting to combine the input of two objects into one form. The
objects are customer and registration. What concerns me is how will I
be able to return the record ID of the customer object to the
registration object so that when the registration object is saved it
contains that customer ID?
I am learning via the book Agile Web D. with Rails (Third
Edition) and in the section on Action view it describes in a section
called “Multiple Models in a Form” a technique used to do this in a
form using the fields_for method. Then in the registration controller
I would specify the creation of a new customer object in the new
action. I would also create in the create action of this controller a
transaction to ensure that (from the book)
- If either model contains invalid data, neither model should be
- If both models contain validation errors, we want to display the
messages from both…
I couldn’t agree more. However in the registration object there is a
field called customer_id that has to be populated with the record_id
from the customer model.
How does one get around this? Thanks for your thoughts in advance.