# Inserting values in two tables at one button click

**URL:** <https://www.ruby-forum.com/t/inserting-values-in-two-tables-at-one-button-click/101130>\
**Category:** Rails\
**Created:** [August 3, 2006, 1:09pm UTC](https://www.ruby-forum.com/t/inserting-values-in-two-tables-at-one-button-click/101130 "2006-08-03T13:09:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kspt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e9c0ed/32.png) [@kspt](https://www.ruby-forum.com/u/kspt)\
**Post date:** [August 3, 2006, 1:09pm UTC](https://www.ruby-forum.com/t/inserting-values-in-two-tables-at-one-button-click/101130/1 "2006-08-03T13:09:20Z")

</div>

hi, i am new to Roby on Rails. we have a project on this. i have very  
much satisfied with development with this environment. it is very  
iteresting.  
but i have a problem with insertion. my problem is: i have to insert  
values into two tables at one submit.  
i am using mysql as db. i have created two tables which has one to one  
reelation ship. once i enter name and email address and role. name and  
emailaddress has to be inserted in users table. with that id role is to  
be inserted in user\_roles table.can any help me in this.

---

<div class="post-metadata">

**Author:** ![kspt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e9c0ed/32.png) [@kspt](https://www.ruby-forum.com/u/kspt)\
**Post date:** [August 4, 2006, 2:41am UTC](https://www.ruby-forum.com/t/inserting-values-in-two-tables-at-one-button-click/101130/2 "2006-08-04T02:41:19Z")

</div>

Have your forms build the data for two tables.

\<%= text\_field ‘modelOne’, 'column %\>  
\<%= text\_field ‘modelTwo’, 'column %\>

— Controller Action

ModelOne.new(params[:modelOne]).save  
ModelTwo.new(params[:modelTwo]).save

That is a super simplified way of doing it. You might want to have some  
checks on save, and validations and such.

-NSHB

On 8/3/06, Ks Ben [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Kind regards,

Nathaniel B.  
President & CEO  
Inimit Innovations Inc. - [http://inimit.com](http://inimit.com)

---

<div class="post-metadata">

**Author:** ![kspt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e9c0ed/32.png) [@kspt](https://www.ruby-forum.com/u/kspt)\
**Post date:** [August 4, 2006, 7:20pm UTC](https://www.ruby-forum.com/t/inserting-values-in-two-tables-at-one-button-click/101130/3 "2006-08-04T19:20:40Z")

</div>

Ks Ben wrote:

> hi, i am new to Roby on Rails. we have a project on this. i have very  
> much satisfied with development with this environment. it is very  
> iteresting.  
> but i have a problem with insertion. my problem is: i have to insert  
> values into two tables at one submit.  
> i am using mysql as db. i have created two tables which has one to one  
> reelation ship. once i enter name and email address and role. name and  
> emailaddress has to be inserted in users table. with that id role is to  
> be inserted in user\_roles table.can any help me in this.

It sounds to me like your real issue is database normalization. Is there  
a compelling reason to repeat the data like this?
