In MVC staffing (for example, Ruby on Rails), do you usually use the model spell as a singular and control spell, and the view spell as a plural?

I usually see Ruby on Rails books using

script/generate model Story name:string link:string 

which is a singular Story , and when it is a controller

 script/generate controller Stories index 

then Story now Stories , which is the plural.

Is this the standard for Ruby on Rails? Is this also true in other MVC environments like CakePHP, Symfony, Django or TurboGears?

I see that in the Rails Space book, the controller is also called User , which matches the model name, and this is the only exception that I see.

Update: also, when the sketch is done in Ruby on Rails, then automatically, the model is singular, and the controller and view are multiple.

+4
source share
2 answers

Rails typically has a very specific format for naming models, controllers, and views, which is not always the only way to complete a task. Rails tradition:

  • Singular models (i.e. history)
  • Plural controllers (i.e. stories)
  • Views are sorted by folder according to the name of the controller (e.g. stories / show.html.erb)

Django seems to use a similar convention with:

  • Models are singular
  • "views" (which are mainly controllers) are not necessarily tied to a specific model.
  • "templates" do not contain a separate agreement, although some of them exist.

Since CakePHP (especially) seems to be behind every Rails, I expect it to follow the same convention.

Regarding the exception, I would suggest that it is related to URL routing. Before Rails 2.3 (I think), Rails routes were automatically set based on the name of the controller (now the router has much more flexibility). Although they could be changed, most people chose not to get confused on the router. I would rather visit yourwebsite.com/user/ to visit my homepage on the login website than yourwebsite.com/users/22.

Remember : agreements exist for some reason, but there are times when agreements are violated reasonably. Keep the “configuration convention” only when it makes sense.

+4
source

This is really your choice, however in Ruby on Rails this is a good convention for choosing singular names for models, so by convention Rails creates nice names for tables, etc. The controllers in Rails usually have the plural, because it creates good routes (URLs), however it does not matter.

+1
source

Source: https://habr.com/ru/post/1310632/


All Articles