Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do rails MVC naming convention work with words which plural form is "-ies" (e.g. replies)?

I was thinking of creating a model called Reply. I was wondering if Rails knows that its plural form is replies and not replys?

like image 249
alexchenco Avatar asked Oct 31 '12 02:10

alexchenco


People also ask

Should Rails controllers be plural?

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 ).

What do naming conventions do in Rails?

2.1 Naming Conventions By default, Active Record uses some naming conventions to find out how the mapping between models and database tables should be created. Rails will pluralize your class names to find the respective database table. So, for a class Book , you should have a database table called books.

Should controllers be plural or singular?

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.

What is naming convention in ruby?

By convention, method names begin with a lowercase letter. (Method names can begin with a capital letter, but that makes them look like constants.) When a method name is longer than one word, the usual convention is to separate the words with underscores like_this rather than using mixed case likeThis .


2 Answers

I believe it internally relies on the pluralize method, so you can check in a rails console what is the result of a particular pluralisation :

"reply".pluralize
=> "replies"

So the answer to your question is yes ;)

like image 58
pjam Avatar answered Nov 16 '22 02:11

pjam


Rails may or may not know the plural form of any word, but if it doesn't you can teach it by adding it to config/initializers/inflections.rb.

like image 24
gaqzi Avatar answered Nov 16 '22 04:11

gaqzi