Rails 控制器应该如何创建?应该是动词、名词还是形容词?
我需要一些建议,创建 Rails 控制器名称时的经验法则是什么?
控制器应该全部是动词还是名词和动词(或形容词)的组合?
这是在Rails中创建控制器时提供的示例,
./script/generatecontrollerCreditCardopendebitcreditclose#它是名词和动词的组合(除非credit和debit变成动词)
但是,如果我创建一个脚手架,默认控制器操作为索引、显示、新建、编辑、更新、销毁,其中有 1 个名词和所有动词。
为了保持一致性并提供更清晰的项目目标,名词和动词是否应该完全分开?或者我应该将它们混合在一起?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
控制器名称应该是复数名词;控制器动作应该是动词。
例如,要使用
open
和close
操作生成CreditCardsController
,您可以使用./script/generate 控制器 CreditCards open close< /代码>。
controller
告诉要生成什么。CreditCards
,命名控制器;仅限复数名词。open close
,命名控制器操作;仅动词。如果您使用
script/generate
而不命名任何操作,则生成器会采用七个 RESTful 默认值,如您所提到的:index show new create edit update destroy
。所有这些都是或者可以是动词。Controller names should be plural nouns; controller actions should be verbs.
For example, to generate
CreditCardsController
with the actionsopen
andclose
, you would use./script/generate controller CreditCards open close
.controller
, tells what to generate.CreditCards
, names the controller; plural nouns only.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.