0

So I think I jacked up my naming conventions (or rather realized I want to do it a different way). I initially created a "Persons" model (which created person.rb). I also created a persons_controller, but apparently rails looks for "People" so I changed the controller name to people_controller.rb (in the files...not in the command line).

I'm new to rails so I really just need to scrap all this and change my names because this setup (having to using Person, Persons, People) throughout the model/controller/views is just a bit confusing for a beginner. All I want to do is change the "Persons" or "People" to the word "Players". So if I were starting from scratch I'd do "rails generate model Player" in the command line, and "rails generate controller Players". But I have no idea how to go about changing my existing controller and model names to this...and I couldn't fully understand some of the older questions related to this topic.

Any help would be greatly appreciated here. Step by Step instruction like your talking to a 12 year old is also highly encouraged given my novice status.

thanks guys,

tereško
  • 58,060
  • 25
  • 98
  • 150
BB500
  • 549
  • 2
  • 6
  • 24
  • Have a look at possible solutions here: http://stackoverflow.com/questions/5672640/rails-renaming-a-controlller-and-corresponding-model – vee Aug 04 '13 at 01:13
  • Perfect - I used the Destroy method from your link...(not sure how I missed that particular question in my search)...appreciate it. – BB500 Aug 04 '13 at 03:00

2 Answers2

1

The basic conventions that will explain everything

About class name and file name

  • Class name must correspond to file path. In English, if you have a Thing model, it must be in models/thing.rb file ; if you have a ThingsController it must be in controllers/things_controller.rb
  • Class name with camel case (i.e SomeThing) must be declared in a file with underscore (i.e some_thing.rb). The file name is written in small letters and underscore is used to "separate" the words. Other example: ThisIsEasyToUnderstand will give this_is_easy_to_understand

About model name, table name and controller name

  • A model name is singular, a table name is plural and a controller is plural. For example a Thing model will have a things table, and will work with a ThingsController controller
  • Rails try at most to use correct English syntax, so a Person model will work with a people table and a PeopleController controller
  • You may have trouble when the model name is, in English, the same in its singular and plural form. Ex: aircraft, eyeglasses, scissors etc.. I won't details the solution to keep my answer clear, but know it can append and you can find solutions on those a bit everywhere on internet.

As an overview:

  • When you create a model, create a name in its singular form
  • When you create a controller create a name in its plural form
  • if you need to rename models or controller you already created you must rename in your code but also rename the file name
  • If you need to rename a model you will also need to rename its table, and you need a migration for that (search google for "rails migration rename table" )

Hope it help for your first steps in Rails

Benjamin Bouchet
  • 12,971
  • 2
  • 41
  • 73
0

You can quickly scrap a model (and its associated files) by calling

rails destroy model [modelname]

Same with controllers, scaffolds, etc.

rails destroy scaffold [modelname]

rails destroy controller [controllername]

Of course, there's no undoing this after you've deleted them, so I'd create the new controllers/models/scaffolds first, migrate any relevant code, and then destroy the useless files.

Amy.js
  • 536
  • 4
  • 11