[英]Rails: What is the convention for controllers with many words
Say I have the model CourseGroup. 假设我有模型CourseGroup。 What would be the controller's name?
控制器的名字是什么?
The controller name would be course_groups_controller
. 控制器名称为
course_groups_controller
。
http://itsignals.cascadia.com.au/?p=7 http://itsignals.cascadia.com.au/?p=7
To find the name for any model, you can open up a rails console and do "ModelName".tableize
. 要查找任何模型的名称,可以打开rails控制台并执行
"ModelName".tableize
。 Then just add "_controller" to the end. 然后只需添加“_controller”到最后。 This would result in
model_names_controller
. 这将导致
model_names_controller
。
Here's an easy way to find out the naming conventions: Just create a throw-away Rails app in a temp directory, with a scaffolded model: 这里有一个简单的方法来找出命名约定:只需在临时目录中创建一个丢弃的Rails应用程序,并使用脚手架模型:
rails blog
cd blog
./script/generate scaffold post subject:string content:text
You can then browse through the files and directories to see how things are named. 然后,您可以浏览文件和目录以查看命名方式。 I like to keep one of these around just to refer to from time to time.
我喜欢保留其中一个,以便不时提及。 And by the way, running the generators without any parameters gives help output which includes examples of naming conventions:
顺便说一句,运行没有任何参数的生成器会提供帮助输出,其中包括命名约定的示例:
./script/generate scaffold
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.