# Creating Tables at RUNTIME

**URL:** <https://www.ruby-forum.com/t/creating-tables-at-runtime/132099>\
**Category:** Rails\
**Created:** [March 17, 2008, 12:41am UTC](https://www.ruby-forum.com/t/creating-tables-at-runtime/132099 "2008-03-17T00:41:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![neo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9fc348/32.png) [@neo](https://www.ruby-forum.com/u/neo)\
**Post date:** [March 17, 2008, 12:41am UTC](https://www.ruby-forum.com/t/creating-tables-at-runtime/132099/1 "2008-03-17T00:41:14Z")

</div>

I am confused about creating tables on runtime…  
suppose i register to one website, and upon successful registration i  
want to create a table with my name like—  
Neo\_Message is the table that i would like to create as soon as i  
press the button name REGISTER. I am using MYSQL as database…Please  
help me… thank you…

---

<div class="post-metadata">

**Author:** ![neo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9fc348/32.png) [@neo](https://www.ruby-forum.com/u/neo)\
**Post date:** [March 17, 2008, 12:52am UTC](https://www.ruby-forum.com/t/creating-tables-at-runtime/132099/2 "2008-03-17T00:52:59Z")

</div>

So you want to create a messages table for the user neo? You know that  
it  
would be much easier to create one messages table for everybody and then  
link that to a specific user by specifying a user\_id field in there as  
well  
as a has\_many :messages on the user model, right?

On Mon, Mar 17, 2008 at 10:10 AM, Neo [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am confused about creating tables on runtime…  
> suppose i register to one website, and upon successful registration i  
> want to create a table with my name like—  
> Neo\_Message is the table that i would like to create as soon as i  
> press the button name REGISTER. I am using MYSQL as database…Please  
> help me… thank you…
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![neo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9fc348/32.png) [@neo](https://www.ruby-forum.com/u/neo)\
**Post date:** [March 17, 2008, 3:14am UTC](https://www.ruby-forum.com/t/creating-tables-at-runtime/132099/3 "2008-03-17T03:14:21Z")

</div>

yes i want to create table for each user. now as u told me … i am  
thinkin should i name those table with user ids or name. also please  
tell me how to do it in rails. i am tryin scaffold method and for that  
i have also installed active scaffold plugin for rails. but still it  
is not able to identify the method “active\_scaffold” . i dont know y…

On Mar 16, 7:52 pm, “Ryan B. (Radar)” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![neo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9fc348/32.png) [@neo](https://www.ruby-forum.com/u/neo)\
**Post date:** [March 17, 2008, 4:41am UTC](https://www.ruby-forum.com/t/creating-tables-at-runtime/132099/4 "2008-03-17T04:41:09Z")

</div>

Yea, you don’t seem to understand relational databases and how data is  
normally stored. Instead of having a new table for each user, you just  
use foreign keys to mark that a particular record belongs to a user.

users table

– id  
– name  
– etc

messages table

– id  
– user\_id  
– text

User model

has\_many :messages

Message model

belongs\_to :user

---

<div class="post-metadata">

**Author:** ![neo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9fc348/32.png) [@neo](https://www.ruby-forum.com/u/neo)\
**Post date:** [March 17, 2008, 3:35am UTC](https://www.ruby-forum.com/t/creating-tables-at-runtime/132099/5 "2008-03-17T03:35:29Z")

</div>

I don’t think you understand me.

I said to have ONE messages table for ALL users and inside that table  
just  
have a user\_id field which references the user.

---

<div class="post-metadata">

**Author:** ![neo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9fc348/32.png) [@neo](https://www.ruby-forum.com/u/neo)\
**Post date:** [March 17, 2008, 1:01pm UTC](https://www.ruby-forum.com/t/creating-tables-at-runtime/132099/6 "2008-03-17T13:01:50Z")

</div>

O… thanks after reading your first reply that thing was going on in  
my mind… well now plans changed… will go your way…

On Mar 16, 10:34 pm, “Ryan B. (Radar)” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![neo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9fc348/32.png) [@neo](https://www.ruby-forum.com/u/neo)\
**Post date:** [March 17, 2008, 1:01pm UTC](https://www.ruby-forum.com/t/creating-tables-at-runtime/132099/7 "2008-03-17T13:01:50Z")

</div>

Thanks for the help… I got it…will ask if i face new problem 🙂

On Mar 16, 11:41 pm, Nathan E. \<rails-mailing-l…@andreas-
