6

I'm creating models that are specific to another model (which will ultimately be embedded in the parent model using Mongoid). Now I'm just stuck with trying to figure out how to name them. I've seen it done both ways, so I don't know what to do:

Singular:

models/
  post.rb
  post/
    comment.rb
    comment/
      happy_comment.rb

class Post

class Post::Comment

class Post::Comment::HappyComment < Post::Comment

Plural:

models/
  post.rb
  posts/
    comment.rb
    comments/
      happy_comment.rb

class Post

class Posts::Comment

class Posts::Comments::HappyComment < Posts::Comment

The benefit to the later is that there can be Posts and Comments modules for wrapping around each child model:

module Posts
  module Comments
    class HappyComment < Comment

What is the correct way to namespace these child models?

Andrew
  • 227,796
  • 193
  • 515
  • 708

1 Answers1

2

There is no generally accepted convention for this and you can use both, depending on what you find better. From technical point of view, Rails will not behave differently in the two situations.

P.S. Are you going to also have other models, named Post, Comment etc.? If not, than maybe the best approach is to just have each model at the top level of your models/ folder.

Alexander Popov
  • 23,073
  • 19
  • 91
  • 130