Rails File Naming Rules

In order to get all of the Rails magic to work, it is important to name files correctly. For instance, if the model names and classes are plural, like “accounts.rb” and “invoices.rb”, then the relationships like :has_one and :belongs_to will not work correctly. However, except for the model name and class, all the other filenames should be plural.

Use Singular Name With Generator

The generators will generate the correct names, but you should give them the singular name like this:

ruby script\generate scaffold account

This will produce the following files:

Controller

accounts_controller.rb

Helpers

accounts_helper.rb

Model

account.rb  (With class Account)

Views

Directory accounts

Mistakenly Using Plural Name

If you make a mistake and call the generator with a plural name, then the model and class will have a plural name, and the relations won’t work correctly. In this case, you can rename the model file and class, but you will also need to rename the class everywhere else it is used.