I've got a problem and am searching for the best solution.
There is a form in my application which asks for data about a firm.
This form consists of three blocks. In the first block I ask for data about a firm (e.g. name, address, etc.), in the second block I ask for data about a department within this firm (name, head, address, etc.). And in the third block I ask for data about printing paper which is used within this department e.g. "Do you use photographic paper for printing", "Do you print black and white" etc.
The questions about the firm and the department have direct counterparts within the database.
for example name of the firm:
table => firm / field => name
But the questions about the printing paper has no direct counterpart within the database. But there is a table for printingpaper which has five fields:
department_id, color, format, alignment, quality
This five fields have to be populated based on the user input. For example when the user answered the question "Do you use photographic paper for printing?" then the fields should be populate in the following way:
department_id => id, color=> true, format => "DIN A4", alignment => "upright", quality => "high"
I need this structure because this application has to be flexible for other requirements.
At the moment I've got a form_for for the firm model and within this form_for a fields_for with nested attributes for the department model and a select_tag for the printing paper question. The form is send to the firm#create action. I accepted nested attributes within the department model for the printing paper model.
How and when do I populate the data to my printing paper table and how do I grab the right department_id. I thought of using Department.last directly after @firm.save in the controller. But It's not 100% sure that I grab the right department object. Is there a best practice for such a case?
Glad for any help :)