Question

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
Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top