Hey guys,
I was wondering what would be the best practice/approach to send ajax request from inside a nested form?
Lemme try to describe it better:
= form_for [@customer, @invoice] do |invoice_form|
= invoice_form.label :date_issue
= invoice_form.text_field :date_issue, :class => ‘datepicker’
= invoice_form.fields_for :item_services do |item_fields|
= item_service.label ‘Search for services’
= item_service.text_field :description
= item_service.submit ‘Search’
= invoice_form.submit ‘Create Invoice’
The outer form is the last to be submitted(creates an Invoice) and in the meanwhile, in the inner form, I’d like to search for an Service and if it doesn’t exists, I’d be rendering some field to create a service and then keep going on the flow.
This is a many-to-many relationship
Invoice ->|--------------|<- ItemService
Invoice has_and_belongs_to_many :item_services
ItemService has_and_belongs_to_many :invoices
Thanks in advance