title: Update parent and add child in Active Record
body: <p>I get a JSON array of records for POST :-</p>
  
  <p>My Parent table model is as follows :-</p>
  
  <pre><code>class UserVehicle &lt; ApplicationRecord
    has_many    :service_bills
  end
  </code></pre>
  
  <p>My child table model is as follows :-</p>
  
  <pre><code>class ServiceBill &lt; ApplicationRecord
      belongs_to  :user_vehicle
  end
  </code></pre>
  
  <p>This is my controller code (to update parent and insert child)</p>
  
  <pre><code>class Api::V1::ServiceBillsController &lt; ApplicationController
  
    def create
      service_bill_params[:user_vehicles].each do |user_vehicle|
        @vehicle = UserVehicle.find_by(vehicle_number:  user_vehicle[:vehicle_number])
  
        if @vehicle
          user_vehicle[:transaction_details].each do |service_bill|
            @service_bill = ServiceBill.create(service_bill)
          end
        else
          p 'vehicle not found'
        end
      end
  
      begin
        if @service_bill.save
          format_response("Ok", 200, "Transaction details inserted successfully.", service_bill_params)
        end    
      rescue =&gt; e
        format_response("Error", 301, e, [])
      end
  
    end
  
  
    private
    def service_bill_params
      service_bill_params = params.require(:service_bill).permit(:user_external_reference, :membership_card_number, user_vehicles: [ :vehicle_number,  :mobile_number, :total_savings, :current_mileage_reading, :last_service_visit, :current_tier, :next_mileage_tier, transaction_details: [:transaction_id, :transaction_external_reference, :total_savings, :amount_paid, :total_bill_amount, :transaction_date] ])
    end
  end
  </code></pre>
  
  <p>The above code does nothing, the terminal says BEGIN and a ROLLBACK immediately. I'm assuming I've missed something with the parent child relationship design?</p>