Любые лучшие практики для следующего?:
У меня есть модель производителя с has_many Inventory
В моей новой форме Inventory мне нужно поле, которое сопоставляется с Manufacturer.name, чтобы при отправке новой формы Inventory приложение:
- searches for a manufacturer with the 'name' from the form
- if it exists then assign the id to @inventory.manufacturer_id and save @inventory
- если он не существует, создайте производителя с «именем» из формы, назначьте идентификатор @inventory.manufacturer_id и сохраните
- have validations work on the new Inventory form
- such that, if the the Inventory form fails validation on a field other than 'name'
- the 'name' field will be repopulated with whatever the user entered (but a new manufacturer is not created unless the form passes validation)
- such that, if the the Inventory form fails validation on a field other than 'name'