Ruby on Rails plural (controller) and singular (model) convention - explanation

前端 未结 5 1573
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 12:31

As per Ruby on Rails convention, controller names get pluralized while model names are singular. Example : a Users controller, but a User model.

rails genera         


        
相关标签:
5条回答
  • 2020-12-07 12:55

    Ruby on Rails follow linguistic convention. That means a model represents a single user, whereas a database table consists of many users.

    0 讨论(0)
  • 2020-12-07 13:00

    An instance of your User model represents a single user, so is singular. The users table, by contrast, holds all of your users, so it's plural.

    0 讨论(0)
  • 2020-12-07 13:11

    in rails conntroller and table name are plural model alone is singular.In a two word name second word is pluralized !

    0 讨论(0)
  • 2020-12-07 13:19

    To complete Emily's answer

    An instance of your User model represents a single user, so is singular. The users table, by contrast, holds all of your users, so it's plural.

    0 讨论(0)
  • 2020-12-07 13:19

    Because the table holds users. Its just the convention.

    0 讨论(0)
提交回复
热议问题