Web Development, Ruby on Rails, DevOps, Git, Tools, Programming, Tips & Tricks

Polymorphic Routes in Rails

 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