Can I use the table name "adm_users" (mysql)? Will that give the model name "adm_user"? Or should it be "admusers" and "admuser"?
on 2006-06-07 12:35
on 2006-06-07 13: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
on 2006-06-07 17:46
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
on 2006-06-07 19:32
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.
on 2006-06-07 22:13
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