Polymorphic Associations

visibility 37 조회수 schedule 14년 전 timer 9:24
open_in_new Dailymotion
Rails has the concept of Polymorphic associations, which are associations that can be of different data types. For example, let’s say we have a Comment model. A comment in your app can be on a post or a page. Rather than creating a PostComment model and a PageComment model, you can set up your Comment model to have a polymorphic association to a Page or a Post.