| Home | Business | Personal | Contact |
||
Max S. Dunn...when there is a will, there is a way |
||
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.
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:
accounts_controller.rb
accounts_helper.rb
account.rb (With class Account)
Directory accounts
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.