I know in Rails we follow conventions. And we should name controllers in plural form.
Recently I hired a freelancer to help me with one part of my application in Rails as I'm really new to this framework and ruby.
I had a PortfolioController
- this is just feels right because portfolio is a container for entries (who says "I have portfolios"?).
The freelancer said it's not right and I will have troubles not following the convention and renamed it to PortfoliosController
. I asked several times what are the exact problems I will have if I name my controller PortfolioController
rather than PortfoliosController
and I didn't get any explanation other than "You will have problems".
So, can anybody tell me what those problems are?
Well, the simplest reason would be that anyone else who works on that project will probably refer to it in the plural while working on the code, then have to realize "oh, they decided to not follow convention in that one controller" after an unspecified time period of "WTF?" while they try to figure out what they are doing wrong. Also semantically, your controller is a controller of ALL the Portfolios in the Portfolio table.
Code-wise you will have issues with routes. You will have to craft a bunch of non-standard routes because
http://my_app/portfolios
goes to theindex
action of the controller by default. You then show a particular portfolio withhttp://my_app/portfolios/1
which will show you the portfolio with theid
of1
. So be prepared to create and maintain a host of custom routes in yourconfig/routes.rb
file. You see similar problems with things that have names that are the same whether plural or singular likeequipment
where you can have one piece of equipment or many pieces of equipment. See this: rails link path and routing error when model singular and plural name are the same (e.g. equipment, species). Not only is it making your routes wonky, it is causing conflicts in methods likeportfolio_path
orportfolio_url
.