# Table names

**URL:** <https://www.ruby-forum.com/t/table-names/95603>\
**Category:** Rails\
**Created:** [June 7, 2006, 10:35am UTC](https://www.ruby-forum.com/t/table-names/95603 "2006-06-07T10:35:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [June 7, 2006, 10:35am UTC](https://www.ruby-forum.com/t/table-names/95603/1 "2006-06-07T10:35:05Z")

</div>

Can I use the table name “adm\_users” (mysql)? Will that give the model  
name “adm\_user”? Or should it be “admusers” and “admuser”?

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [June 7, 2006, 11:24am UTC](https://www.ruby-forum.com/t/table-names/95603/2 "2006-06-07T11:24:39Z")

</div>

PÃ¥l BergstrÃ¶m wrote:

> Can I use the table name “adm\_users” (mysql)? Will that give the model  
> name “adm\_user”? Or should it be “admusers” and “admuser”?

I would recommend using admin\_users as your table name

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [June 7, 2006, 3:46pm UTC](https://www.ruby-forum.com/t/table-names/95603/3 "2006-06-07T15:46:18Z")

</div>

Hi PÃ¥l,

PÃ¥l BergstrÃ¶m wrote:

> Can I use the table name “adm\_users” (mysql)?  
> Will that give the model name “adm\_user”?

Here’s what I did to get an answer to your question.

1. Create a ‘sandbox’ app. Open a command window and go to the  
rails\_apps  
directory and enter\> rails sandbox  
This creates the entire directory structure for the app in/under a  
directory  
named sandbox

2. Create a database named sandbox (I use MySQL front for this)

3. In the sandbox\db directory, create an empty file named create.sql.

I did the three steps above once, quite a while ago. The steps below I  
do  
every time I have a question like yours that I can’t find out using irb  
or  
ruby script\console

1. To answer your question, I modified the create.sql file to contain  
the  
following content.

drop table if exists adm\_users;

create table adm\_users (  
id int not null auto\_increment,  
name varchar(20) null default ‘’,  
primary key (id)  
) engine=InnoDB;

1. In the sandbox directory, enter\>mysql sandbox \<db\create.sql  
This create the adm\_users table in the sandbox database.

2. In the sandbox directory, enter\> ruby script\generate scaffold  
adm\_user  
admin.  
This tells RoR to generate the model, controller, and views for my app  
and  
to name the model adm\_user and to name the controller admin\_controller.  
This was accomplished without error messages. Good sign.

3. In the command window, start WEBrick by entering \>ruby script\server

8 Open a browser window to [http://localhost:3000/admin](http://localhost:3000/admin) and see if the  
little  
app works.

Sure enough, RoR looks to have no initial issues with an underscore in  
the  
model name. I say initial because, knowing that RoR favors convention  
over  
configuration, there is some possibility that this might cause me future  
grief WRT using some of the Rails magic. But your question wasn’t about  
Rails conventions, it asked if something specific would work. The  
conventions are discussed on the wiki and in the books.

hth,  
Bill

PS. I’ve found that if I do stuff like the above prior to posting a  
question here, I get several benefits.  
a) I usually find out the answer to my question more quickly than  
posting  
and waiting for a response. As you can see from the above, it took five  
steps (since I’d already done the first three) to get a confirmed answer  
to  
your question. It took far less time than writing this email.  
b) I’m able to help other newbies to the list who haven’t yet figured  
out  
how easy it is just to try something out in RoR.  
c) I’ve found that by avoiding (a) and doing (b), the folks here who  
know  
the answers to the questions I really _can’t_ figure out on my own seem  
more  
willing to help.

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [June 7, 2006, 5:32pm UTC](https://www.ruby-forum.com/t/table-names/95603/4 "2006-06-07T17:32:56Z")

</div>

Bill W. wrote:

> Hi PÃ¥l,
> 
> PÃ¥l BergstrÃ¶m wrote:
> 
> > Can I use the table name “adm\_users” (mysql)?  
> > Will that give the model name “adm\_user”?
> 
> ) Create a database named sandbox (I use MySQL front for this)

the answers to the questions I really _can’t_ figure out on my own seem

> more  
> willing to help.
> 
> Best regards,  
> Bill

Hi Bill,

Thank you for your thorough answer. 🙂

The thing is I have a lot of tables separated in different modules (a  
php solution) that I differentiate by the first part of the name. My  
idea is to translate this into RoR.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [June 7, 2006, 8:13pm UTC](https://www.ruby-forum.com/t/table-names/95603/5 "2006-06-07T20:13:55Z")

</div>

I find it’s best to seperate words with underscores. That way, rails  
will also configure the “human readable” version properly, ie:  
“admin\_users” becomes “Admin User”, and the associated model will be  
AdminUser.  
-Nathan
