Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: What is the convention for controllers with many words

Say I have the model CourseGroup. What would be the controller's name?

like image 990
Nerian Avatar asked Jan 27 '26 02:01

Nerian


2 Answers

The controller name would be course_groups_controller.

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. Then just add "_controller" to the end. This would result in model_names_controller.

like image 118
zsalzbank Avatar answered Jan 28 '26 15:01

zsalzbank


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 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
like image 24
Dogweather Avatar answered Jan 28 '26 17:01

Dogweather



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!