Naming Conventions

Get familiar with some of the conventions of writing controller and view names in Ruby.

Newcomers to Rails are sometimes puzzled by the way it automatically handles naming. They’re surprised that they call a model class Person and Rails somehow knows to go looking for a database table called people. In this lesson, we’ll learn how this implicit naming works.

The rules here are the default conventions used by Rails. We can override all of these conventions using configuration options.

Mixed case, underscores, and plurals

We often name variables and classes with short phrases. In Ruby, the convention is to have variable names where the letters are all lowercase and words are separated by underscores. Classes and modules are named differently, in that there are no underscores and each word in the phrase, including the first, is capitalized. This is called “mixed case,” for fairly obvious reasons. These conventions lead to variable names such as order_status and class names such as LineItem.

Rails take this convention and extend it in two ways. First, it assumes that database table names, such as variable names, have lowercase letters and underscores between the words. Rails also assume that table names are always plural. This leads to table names such as orders and third_parties.

On another axis, Rails assumes that ...