On 1/2/06, Andy P. email@example.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