# Form should insert on 2Tables in my DB

**URL:** <https://www.ruby-forum.com/t/form-should-insert-on-2tables-in-my-db/196718>\
**Category:** Rails\
**Created:** [June 19, 2008, 2:13pm UTC](https://www.ruby-forum.com/t/form-should-insert-on-2tables-in-my-db/196718 "2008-06-19T14:13:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![viliwort](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/bc8723/32.png) [@viliwort](https://www.ruby-forum.com/u/viliwort)\
**Post date:** [June 19, 2008, 2:13pm UTC](https://www.ruby-forum.com/t/form-should-insert-on-2tables-in-my-db/196718/1 "2008-06-19T14:13:26Z")

</div>

Hi to you!

I’m writing my first webapp with ruby on rails. And I like it so far.

My problem is:  
I have a form and if I create a db-record, that works fine.  
But I want to create 2 records on 2 different tables (with one form).

Example (a phone book app):  
I have a table person and a table place.

On the form “new person” I have the fields  
Name, first name… and the field place.  
Now I want to insert the Name, first name… on the table person  
and insert the new place on the table place.

Questions:  
Is that possible?  
How should the form look like?  
How can I handle this in the controller?

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![viliwort](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/bc8723/32.png) [@viliwort](https://www.ruby-forum.com/u/viliwort)\
**Post date:** [June 19, 2008, 2:33pm UTC](https://www.ruby-forum.com/t/form-should-insert-on-2tables-in-my-db/196718/2 "2008-06-19T14:33:28Z")

</div>

As so often, there are many ways to do this.  
You can use a form\_for and add some additional fields or  
build the whole form with a simple form\_tag

the most simple form for a client with a name and an  
additional address record would look like this

\<% form\_tag(admin\_clients\_path) do %\>  
\<%= text\_field :client, :name, :size =\> 20 %\>  
\<%= text\_field :address , :city, :size =\> 40 %\>  
\<% end %\>

in you controller you get params as this  
params[:client][:name]  
params[:address][:city]

and can do the common stuff like  
Client.new(params[:client])  
Address.new(params[:address])
