3

I need some advice, what is the rule of the thumb when creating Rails controllers names?

Should controller be all be verbs or a combination of nouns and verbs (or adjectives)?

This is the example provided on creating controllers in Rails,

./script/generate controller CreditCard open debit credit close # which is a combination of nouns and verbs (unless credit and debit is made into a verb)

However, if I create a scaffold, the default controller actions would be index, show, new, edit, update, destroy, which has 1 noun and all verb.

Should nouns and verbs be separated completely for sake of consistency also providing a clearer project goals? Or should I mix them together?

Winston
  • 225
  • 1
  • 2
  • 7

1 Answers1

4

Controller names should be plural nouns; controller actions should be verbs.

For example, to generate CreditCardsController with the actions open and close, you would use ./script/generate controller CreditCards open close.

  • The first argument, controller, tells what to generate.
  • The second argument, CreditCards, names the controller; plural nouns only.
  • The remaining arguments, open close, name the controller actions; verbs only.

If you use script/generate without naming any actions, the generator assumes the seven RESTful defaults, as you mentioned: index show new create edit update destroy. All of these are, or can be, verbs.

Ron DeVera
  • 13,578
  • 5
  • 39
  • 36