On 26 Mar., 17:54, eengnerd <[email protected]> wrote:
> The following command issued at the terminal prompt for a Rails
> project should create a PostGreSQL table with the actual Table Name of
> Customers, but instead it creates a Table Name of customers. This is
> extremely disconcerting to me. Especially when I discovered that
> after using single quote marks (in the hope of remedying this), the
> command could not succeed in creating the other "serialization table"
> for tracking the autoincrementing id field.
>
> The command in question:
>
> ruby script/generate scaffold Customer LegalName:string Address:string
> City:string State:string PostalCode:string
>
> The real surprise was that the field name cases were actually
> preserved! But not the Table Name. I don't know why, but apparently
> there are a lot of programmers who think that "case does not matter"
> where table names are concerned. But they matter a Great Deal to
> me...ok?
In Rails there is a set of naming conventions you need to use, in
order to make the development process of your Rails application
painless. Tables are plural nouns in snake case. Models are singular
nouns in camel case. These two conventions were made to enable Rails
to automatically detect the name of a table, based on the name of a
model.
RacingCar model => racing_cars table.
This kind of strict conventions does not exist for column names,
because Rails doesn't have to link them up to something else. Even
though, it's recommended to name your columns with snake case. If you
really, really want to get around this, you can go to the migration
file that the scaffold generator created for you and edit the table's
name manually and then, in your model, add this line:
set_table_name "Customers"
(But I hope you'll learn to accept the naming conventions of Rails,
soon.)
--
Best regards,
David Knorr
http://twitter.com/rubyguy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---