# Updating mutiple tables from the same form

**URL:** <https://www.ruby-forum.com/t/updating-mutiple-tables-from-the-same-form/88235>\
**Category:** Rails\
**Created:** [March 9, 2007, 2:33am UTC](https://www.ruby-forum.com/t/updating-mutiple-tables-from-the-same-form/88235 "2007-03-09T02:33:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![georgeuoa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ab992/32.png) [@georgeuoa](https://www.ruby-forum.com/u/georgeuoa)\
**Post date:** [March 9, 2007, 2:33am UTC](https://www.ruby-forum.com/t/updating-mutiple-tables-from-the-same-form/88235/1 "2007-03-09T02:33:22Z")

</div>

Hi Guys!

Does anyone have an idea on how to update fields in different tables  
using a single form?

Say i have 3 tables and i wanted to create new entries and update them  
from a single form. how can i build such a model?

diffent textboxes in the form should create new entries in the various  
table with only a single create button click on one form.

Thanks

Tanzanite

---

<div class="post-metadata">

**Author:** ![georgeuoa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ab992/32.png) [@georgeuoa](https://www.ruby-forum.com/u/georgeuoa)\
**Post date:** [March 9, 2007, 3:59am UTC](https://www.ruby-forum.com/t/updating-mutiple-tables-from-the-same-form/88235/2 "2007-03-09T03:59:03Z")

</div>

Thanks!  
I will try it and see how it works out.

tz

---

<div class="post-metadata">

**Author:** ![georgeuoa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ab992/32.png) [@georgeuoa](https://www.ruby-forum.com/u/georgeuoa)\
**Post date:** [March 9, 2007, 3:43am UTC](https://www.ruby-forum.com/t/updating-mutiple-tables-from-the-same-form/88235/3 "2007-03-09T03:43:55Z")

</div>

You have to use the fields\_for tag for this, in the following code I  
have two models. One for account and the other is for BillingProfile.  
This code uses Rails 1.2.2.

\<%= error\_messages\_for :account %\>

\<% form\_for :account, @a, :url =\> account\_path(@account), :html =\>  
{ :method =\> :put } do |f| %\>

 Account Information 

Package: \<%= f.select :package, Account::PACKAGE\_TYPES, :prompt =\> "Select a package" %\>

Upgrade Database: \<%= f.select :db\_limit, Account::DATABASE\_LIMITS, :prompt =\> "Select database limit" %\>

 Billing Information \<% fields\_for :billing\_profiles do |billing\_profile| %\> 

**Name**  
 \<%= billing\_profile.text\_field :name %\>

**Email**  
 \<%= billing\_profile.text\_field :email %\>

**Business phone**  
 \<%= billing\_profile.text\_field :business\_phone %\>

**Home phone**  
 \<%= billing\_profile.text\_field :home\_phone %\>

**Company**  
 \<%= billing\_profile.text\_field :company %\>

**Address1**  
 \<%= billing\_profile.text\_field :address1 %\>

**Address2**  
 \<%= billing\_profile.text\_field :address2 %\>

**City**  
 \<%= billing\_profile.text\_field :city %\>

**State**  
 \<%= billing\_profile.text\_field :state %\>

**Zip**  
 \<%= billing\_profile.text\_field :zip %\>

**Country**  
 \<%= billing\_profile.country\_select :country, ["United States"] %\>

 \<% end %\> 

\<%= submit\_tag "Upgrade My Account" %\>

\<% end %\>

On Mar 8, 8:33 pm, Tanzanite T. \<rails-mailing-l…@andreas-
