Riveascore
Riveascore

Reputation: 1852

Rails submit different fields to different controllers in form

I have a form setup and want it so that:

name, address (and other address details) submit to my BillingAddress

While

credit_card_number etc would submit to PaymentMethod

I'm using things such as f.text_field for my form fields.

But, my payment method has a billing_address_id, so I would like it to submit the specified data to BillingAddress, create that new instance, then assign its id to PaymentMethod while also submitting that other data to PaymentMethod.

Sidenote: I understand I should save credit card numbers in the db, I will use a gem later on to handle holding this data properly, but for now, I just want to get the basic structure down.

Upvotes: 0

Views: 57

Answers (1)

Sampat Badhe
Sampat Badhe

Reputation: 9085

use this while creating BillingAddress

@billing_address = BillingAddress.create(params[:billingaddress])
@billing_address.payment_method.create(payment_method_params)

Upvotes: 1

Related Questions