if i've got a thread model and controller.
should that be in singular or plural for both the model and controller?
i could show a thread and also list threads.
dont know what i should use.
$thread->get_lists(); // doesnt sound good
$threads->show(); // doesnt sound good
Controller names are either singular or plural : Using “rails g resource” names the controllers plural, which makes sense because I think about them controlling many routes. Resource names are singular : They create a lot of mvc framework, the name you pass will become the model name, and let rails pluralize the rest.
The Controller suffix is always singular. The name of the resource is usually plural. Controller actions use snake_case and usually match the standard route names Rails defines ( index , show , new , create , edit , update , delete ).
controller (plural controllers)
You use singular names because each class represents a generalized version of a singular object.
It doesn't matter.
I personally use singular for models and plural for controllers.
What matters, however, is that you pick a scheme and be consistent.
That depends on the model. If objects of that class represent exactly one thing, use singular, if they represent many things, use plural (but you usually do not need such a class, use an array/a collection). Both cannot happen or you should redesign (1).
I'll use your Thread example:
If every object models one thread, name the class "Thread". If it models several threads at once, call it "Threads" (or "ThreadCollection" or the like).
(1) If you need both, a representation of a single thread and a representation of many threads at once, use two distinct classes (Thread and Threads) or create an array or a collection for the latter. Then you'll have it clean: $thread->show(); $threads->list();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With