Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails controller naming convention postsComments or postComments

If I'd like to generate a controller for comments that belongs to a post which in turn belongs to a user, should I name this

rails g controller postsComments

Or

rails g controller postComments

Or

rails g controller postcomments

Or just

rails g controller comments
like image 601
Tanapuch Touchdown Avatar asked May 08 '26 10:05

Tanapuch Touchdown


2 Answers

If you type,

 rails g controller 

you'll get detailed instructions and an example of how to do it correctly. Basically, you can use either CamelCase or under_scored and the result will be the same. under_scores in file names and CamelCase in class names.

As for the name, I'd personally use Comments, unless you plan to have another type of comments in your app and want to use a different class name for them.

And finally the question whether you should use PostsComments or PostComments is more about the english language than Rails. I think the more correct way would be PostComments, but I'm not a native speaker :)

like image 135
Matt Avatar answered May 10 '26 01:05

Matt


I would use the rails g controller PostComments command, post singularized because Post has_many Comments & Comment has_one Post.

like image 41
MrYoshiji Avatar answered May 10 '26 01:05

MrYoshiji



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!