I was thinking of creating a model called Reply
. I was wondering if Rails knows that its plural form is replies
and not replys
?
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 ).
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.
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.
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 .
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 ;)
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
.
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