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