# Copy contents from one table to the other

**URL:** <https://www.ruby-forum.com/t/copy-contents-from-one-table-to-the-other/113828>\
**Category:** Rails\
**Created:** [September 5, 2007, 11:44am UTC](https://www.ruby-forum.com/t/copy-contents-from-one-table-to-the-other/113828 "2007-09-05T11:44:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhaval\_parikh33](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bcef8e/32.png) [@dhaval\_parikh33](https://www.ruby-forum.com/u/dhaval_parikh33)\
**Post date:** [September 5, 2007, 11:44am UTC](https://www.ruby-forum.com/t/copy-contents-from-one-table-to-the-other/113828/1 "2007-09-05T11:44:44Z")

</div>

hello frnds

I want to first connect to one table then fetch the desired  
value…store that in variable and then copy the contents of that  
variable to another table. Can you tell me how to do that?

Thanks

Dhaval P.

---

<div class="post-metadata">

**Author:** ![dhaval\_parikh33](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bcef8e/32.png) [@dhaval\_parikh33](https://www.ruby-forum.com/u/dhaval_parikh33)\
**Post date:** [September 5, 2007, 12:02pm UTC](https://www.ruby-forum.com/t/copy-contents-from-one-table-to-the-other/113828/2 "2007-09-05T12:02:53Z")

</div>

ok let me understand it  
dhval has table\_1 and table\_2  
hes saving some fields in table\_1 which is in the  
instance\_variable(object)  
called abc  
now he wants to save the contents of object abc in table\_2  
ok  
in this case we can use after\_save  
which saves the passed parameters in the mentioned table from table 1  
i hope it works  
do mail me back if it doenst  
have fun

On 9/5/07, Dhaval P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## Dhaval P.
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Piyush  
09916133729

> **[Three finger salute](http://ctrlshiftesc.blogspot.com/)**
>
> I think, therefore I Am...said Descartes! 
> 
> I Am, therefore I will think...said Ayn Rand! 
> 
> I think I Am, therefore I think I am thinking...says The Common Man!!!

---

<div class="post-metadata">

**Author:** ![dhaval\_parikh33](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bcef8e/32.png) [@dhaval\_parikh33](https://www.ruby-forum.com/u/dhaval_parikh33)\
**Post date:** [September 5, 2007, 12:54pm UTC](https://www.ruby-forum.com/t/copy-contents-from-one-table-to-the-other/113828/3 "2007-09-05T12:54:58Z")

</div>

Yes what you have understood is perfect but then can you give me an  
example with coding then that will be gr8 as i havent used after\_save  
method b4…

Thanks

Dhaval P.

---

<div class="post-metadata">

**Author:** ![dhaval\_parikh33](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bcef8e/32.png) [@dhaval\_parikh33](https://www.ruby-forum.com/u/dhaval_parikh33)\
**Post date:** [September 5, 2007, 2:31pm UTC](https://www.ruby-forum.com/t/copy-contents-from-one-table-to-the-other/113828/4 "2007-09-05T14:31:38Z")

</div>

have A loook at [http://api.rubyonrails.org/](http://api.rubyonrails.org/)  
sarch for after\_save  
then u can pass the parametrs which you want to

somewhat like  
Table2.create(:table1\_id =\> table1\_id,  
:id =\> table1.id,  
)

i hope it works  
u may use after\_create  
check the api link and figure out which suits u the best

see ya  
have fun

On 9/5/07, Dhaval P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Piyush  
09916133729

> **[Three finger salute](http://ctrlshiftesc.blogspot.com/)**
>
> I think, therefore I Am...said Descartes! 
> 
> I Am, therefore I will think...said Ayn Rand! 
> 
> I think I Am, therefore I think I am thinking...says The Common Man!!!

---

<div class="post-metadata">

**Author:** ![dhaval\_parikh33](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bcef8e/32.png) [@dhaval\_parikh33](https://www.ruby-forum.com/u/dhaval_parikh33)\
**Post date:** [September 5, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/copy-contents-from-one-table-to-the-other/113828/5 "2007-09-05T15:12:19Z")

</div>

Thanks again

this is much clearer but the thing is that i dont want to create table  
dynamically.I just want to copy the contents to a table that is already  
created say suppose i have one value in @email which stores the email  
address then i want to copy that value to the email field in table2 the  
structure of which is already created…hope this is clear

thanks

Dhaval P.
