I want to save the credit card information (token) in the purchases table and the address in the addreses table, but it doesn't work like the image. What should i do?

Problems/errors that are occurring Applicable source code
class Address
class Purchase
class PurchaseAddress
class AddressesController
What I tried myself

Description of Form object, confirmation of association of each model

  • Answer # 1

    The save method of the purchase_address model
    def save
    @purchase_address = Purchase.create (user_id: user_id, item_id: item_id)
    Address.create (post_number: post_number, municipality: municipality, prefecture_id: prefecture_id, addresses: addresses, build_name: build_name, phone_number: phone_number, purchase_id: @ purchase_address.id)
    It was fixed!