rails
Polymorphic Routes in Rails
In Rails, you can define a model as polymorphic like the following: class Post has_many :comments, as: :commentable end class NewsItem has_many :comments, as: :commentable end class Comment belongs_to :commentable, polymorphic: true end And I believe your resources would look like this: resources :posts resources :comments end