Table names

Can I use the table name “adm_users” (mysql)? Will that give the model
name “adm_user”? Or should it be “admusers” and “admuser”?

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

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 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

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. :slight_smile:

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.

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