Forum: Ruby on Rails Naming Conventions

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.
724a9d1d0244e08cb4be518c88648d9f?d=identicon&s=25 Andy Park (prot)
on 2006-01-02 21:06
So, RoR is better at grammer than I. Well so is my nine year old.

If I have a table named "people_type" will Rails see this as singular
because of the _type or will it consider it the plural of "person_type"
?

Is there a link to Rails that lists what words it knows, or what words
not to use in table design etc.

Kindest regards.
8e44c65ac5b896da534ef2440121c953?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-01-02 22:54
(Received via mailing list)
On Jan 2, 2006, at 12:06 PM, Andy Park wrote:

> Kindest regards.
>
> --
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


Andy-

	Topfunky has put up an excellent tool for figuring out what rails
thinks the plural of a word is. You can find it here:

http://nubyonrails.com/tools/pluralize


Cheers-
-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
ezra@yakima-herald.com
509-577-7732
5b9fe87ec1faa67a4599782930f45ec9?d=identicon&s=25 Sam Stephenson (Guest)
on 2006-01-02 22:54
(Received via mailing list)
Hi Andy,

On 1/2/06, Andy Park <celtichuddle@mac.com> wrote:
> So, RoR is better at grammer than I. Well so is my nine year old.
>
> If I have a table named "people_type" will Rails see this as singular
> because of the _type or will it consider it the plural of "person_type"
> ?
>
> Is there a link to Rails that lists what words it knows, or what words
> not to use in table design etc.

You can use Ruby to find out how Rails' naming conventions work:

| % script/console
| Loading development environment.

What table name should be used for the PersonType model?

| >> "PersonType".tableize
| => "person_types"

What model does the table named "people_type" map to?

| >> "people_type".classify
| => "PeopleType"

Does this match what Rails expects for the PeopleType model?

| >> "PeopleType".tableize
| => "people_types"

No -- if the model is called PeopleType, we need to use "people_types"
for the table name instead. You can make a method which automates this
check for you:

| >> class String
| >>   def canonical_table_name?
| >>     self == classify.tableize
| >>   end
| >> end
| => nil
| >> "person_types".canonical_table_name?
| => true
| >> "people_type".canonical_table_name?
| => false

--
sam
724a9d1d0244e08cb4be518c88648d9f?d=identicon&s=25 Andy Park (prot)
on 2006-01-02 23:12
Sam, Ezra

Outstanding! thankyou both, great information.

Regards.
724a9d1d0244e08cb4be518c88648d9f?d=identicon&s=25 Andy Park (prot)
on 2006-01-03 01:29
Which now leads me to...

If I have two tables

"people"
- id
- name

&

"person_types"
- id
- kind

Am I right in thinking that the row in "person" linking too
"person_types" should be ;

"people"
- id
- name
- PersonType_id (as opposed to "person_types_id")

Again, many thanks for your time.

Kindest reagrds.
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-01-03 01:38
(Received via mailing list)
On Jan 2, 2006, at 7:29 PM, Andy Park wrote:

> "person_types"
> - id
> - kind
>
> Am I right in thinking that the row in "person" linking too
> "person_types" should be ;
>
> "people"
> - id
> - name
> - PersonType_id (as opposed to "person_types_id")

Stranger yet. :-)

person_type_id, because it only points to one type. :-)

--
-- Tom Mornini
724a9d1d0244e08cb4be518c88648d9f?d=identicon&s=25 Andy Park (prot)
on 2006-01-03 01:48
Thanks Tom.

I think I need to watch The Life of Brian again. Remember the bit with
the Centurian, when Brian is writing graffiti on the palace wall? The
Centurion catches him in the act.

Centurion: What's this, then? "Romanes eunt domus"? People called
Romanes, they go, the house?

Brian: It says, "Romans go home. "

Centurion: No it doesn't ! What's the latin for "Roman"? Come on, come
on !

Brian: Er, "Romanus" !

Centurion: Vocative plural of "Romanus" is?

and on it goes ....
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-01-03 03:17
(Received via mailing list)
:-)

--
-- Tom Mornini
25bbc96d9c53647354cb724e744b2222?d=identicon&s=25 Greg Freemyer (Guest)
on 2006-01-04 02:12
(Received via mailing list)
For my first RoR test app I tried to use the table "books".

The singular form I wanted was invoice, credit report, payment, etc.

Happily I realized the futulity of this before I even got started.

I still plan to do something real along the lines of the above.  Maybe
"records"?

On 1/2/06, Andy Park <celtichuddle@mac.com> wrote:
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Greg Freemyer
The Norcross Group
Forensics for the 21st Century
17acfbd3a05cfb59e0543235cc0a813b?d=identicon&s=25 joshua (Guest)
on 2006-01-04 05:47
Andy Park wrote:
> If I have a table named "people_type" will Rails see this as singular
> because of the _type or will it consider it the plural of "person_type"?

If your terminology is awkward to use, it may indicate a poor choice for
the term. Why don't you consider a term that more naturally reflects the
concept, such as "role", "officer_grade" or "job_description"? In a
journalism class I was told to avoid using the word "people" as it is
usually too generic, and I find that advice serves me well in model
terminology as well.

By the way, someone should let the Rails pluralizer know that the plural
of mother_in_law is mothers_in_law :-)
724a9d1d0244e08cb4be518c88648d9f?d=identicon&s=25 Andy Park (prot)
on 2006-01-04 05:58
joshua wrote:

> If your terminology is awkward to use, it may indicate a poor choice for
> the term. Why don't you consider a term that more naturally reflects the
> concept, such as "role", "officer_grade" or "job_description"? In a
> journalism class I was told to avoid using the word "people" as it is
> usually too generic, and I find that advice serves me well in model
> terminology as well.

Noted, and I agree, but.....

A  "person" may be or have a

     -- role
     --- officer_grade
     ---- job_description

I understand what you are saying and I like the way Rails makes you
really think "Naming" something rather seriously.
C85ca2a8a596bb74f1d3519de9fea8a4?d=identicon&s=25 Nika Ta (aiko334)
on 2006-06-14 20:52
Hi Everyone,

I'm having problem with naming conventions.
I've 2 tables (states and steps), states has id, name, message, and
step_id
but when I go to http://127.0.0.1:3000/state it only pulls up the first
3 columns.
If I change step_id to stepid, it will show up but I want to be able to
show db info with names with underscore. How can this be dones?
Thanks,
Nika

random at tangaz dot net


Andy Park wrote:
> Which now leads me to...
>
> If I have two tables
>
> "people"
> - id
> - name
>
> &
>
> "person_types"
> - id
> - kind
>
> Am I right in thinking that the row in "person" linking too
> "person_types" should be ;
>
> "people"
> - id
> - name
> - PersonType_id (as opposed to "person_types_id")
>
> Again, many thanks for your time.
>
> Kindest reagrds.
6ef8cb7cd7cd58077f0b57e4fa49a969?d=identicon&s=25 Brian Hogan (Guest)
on 2006-06-14 22:03
(Received via mailing list)
That's not related to naming conventions. That is related to how
scaffolding
works.  Please make a new post for this if you require more help.
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-06-15 06:07
(Received via mailing list)
Nika Ta wrote:

> I'm having problem with naming conventions.
> I've 2 tables (states and steps), states has id, name, message, and
> step_id
> but when I go to http://127.0.0.1:3000/state it only pulls up the first
> 3 columns.
> If I change step_id to stepid, it will show up but I want to be able to
> show db info with names with underscore. How can this be dones?

This is just a guess, but it may be that RoR is interpreting step_id as
a
reference (i.e., a foreign key) to the steps table.  What do your
state_controller.rb index method and state/index.rhtml file look like?

hth,
Bill
This topic is locked and can not be replied to.