24 Nov '12, 5am

#rails polymorphic associations

Above is a page from a site that has three different models: articles, photos and events. We’d like to enhance the site so that its users can add comments to an article, a photograph or an event. If we were just adding comments to one of the models, say articles we’d create a Comment model and have a has_many / belongs_to relationship between Article and Comment . Without polymorphic associations we’d have to create three different types of comment model so that each one could belong_to the appropriate model, which would create a lot of repetition in the code. Polymorphic associations allow us to create just one Comment model and have each comment know which other model it should be associated with.

Full article: http://asciicasts.com/episodes/154-polymorphic-association

Tweets

Episode 394: STI and Polymorphic Associations (...

railscasts.com 26 Nov '12, 4am

#394 STI and Polymorphic Associations Nov 25, 2012 | 14 minutes | Refactoring , Active Record Single Table Inheritance (ST...

ASCIIcasts - Episode 288 - Billing With Stripe ...

asciicasts.com 24 Nov '12, 2am

Stripe needs two API keys so that it knows which account it’s working with. We’ll store these in a new stripe.rb initializ...