Just notes about some of the naming conventions used by Rails. I pulled this info from various sources and filled in the rest.
Model/Class Table/Schema
- Table (in database) – Plural, with underscores instead of spaces between words (ie: steering_wheels)
- Model / Class – Singular, first letter Capitalized, CamelCase for models (ie: SteeringWheel)
- Model/Class Table/Schema
- Order orders
- LineItem line_items
- Person people
- Address addresses
- Legacy legacies
- Mouse mice
- *Foreign key fields are named… tablename_id (i.e. customers_id, orders_id)
- *id (Every table automatically gets a key field of “id” (just plain old “id”))
- *created_at, created_on, updated_at, updated_on (IF USED, rails will automatically update these fields)
- *lock_version (IF USED, automatic field used for “optimistic locking”) (integer, default=0, null=false)
- *counter_cache (field used to save database lookups)
- *type (IF USED, allows “single table inheritence”)
- *mytable_count (IF USED, allows rails to calculate the # of objects created for the class) (when you define it, make it default to zero)
- *position (IF USED, “position” is used when sorting objects in a “acts_as_list” class)
- *parent_id (IF USED, foreign key column in an “acts_as_tree” model)
- *lft and rgt (IF USED, provides nested set enhanced tree-like functionality “acts_as_nested_set”)
- quote_value
- template
Controllers
- Class Name File Name
- WeblogsController weblogs_controller.rb
- LineItemsController line_items_controller.rb
Views
- Folder Name File Name
- web_logs index.rhtml (this is just the default, any number of html files can exist here)
- line_items index.rhtml
- /app/views/orders/index.rhtml
- Helper:
- /app/helpers/orders_helper.rb
- Module Name = OrdersHelper
- To access the view from a browser, if you are using index.rhtml, you just need to specify the view folder name:
- *If you create a file at app/views/layouts/application.rhtml it will automatically be used as a wrapper around all other layouts.
[...] to roll back to a prior version! See my “Naming Conventions” Post for more info: http://oomoo.wordpress.com/2008/03/11/some-rails-naming-conventions/ [...]
Pingback by Create A New Migration Script « Oomoo — March 20, 2008 @ 7:32 pm
Thanks for that ! I was looking for it since a while. This Friday 13 was a good day.
bruno
Comment by bruno duyé — June 13, 2008 @ 4:53 pm