Reputation: 1833
I want to design a registration form for new customer. The rails way I know is to create a "customer" model with all attributes of customer and then write a controller and html.erb. The challenge I have is that the attributes of a customer are in multiple DB tables. I need a way to create a model that is joint of multiple tables and when I commit, it saves to multiple tables. any tips will be appreciated.
Upvotes: 1
Views: 228
Reputation: 38062
Extracting your model into multiple models is the simplest way to do this. For example, if your database has 'Customer', 'Address' and 'Location' tables create a 'Customer' model that has one 'Address' and has one 'Location'. Then in your form, use a nested model form for creating and updating. This tutorial is a good starting place:
Upvotes: 3