Forum: Ruby on Rails Table names

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3275da7fdbd73cb4e7956fd0d29164de?d=identicon&s=25 Paul Bergstrom (palb)
on 2006-06-07 10:35
Can I use the table name "adm_users" (mysql)? Will that give the model
name "adm_user"? Or should it be "admusers" and "admuser"?
B5a793b425c4db1f45c3cdfec5697047?d=identicon&s=25 scott (Guest)
on 2006-06-07 11:24
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
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-06-07 15:46
(Received via mailing list)
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

4) 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;

5) In the sandbox directory, enter>mysql sandbox <db\create.sql
This create the adm_users table in the sandbox database.

6) 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.

7) 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
3275da7fdbd73cb4e7956fd0d29164de?d=identicon&s=25 Paul Bergstrom (palb)
on 2006-06-07 17:32
Bill Walton 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.
D5145c421cd25af6fa577c15219add90?d=identicon&s=25 unknown (Guest)
on 2006-06-07 20:13
(Received via mailing list)
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
This topic is locked and can not be replied to.