Creating Polymorphic Columns in a Rails (2+) Migration
This is a small convenience, but I just discovered it so I thought I’d share. The following migration will add an attachment_id column and a string attachment_type column with a default value of ‘Photo’.
You can also use belongs_to instead of references if that seems more intuitive; It will have the same effect. For more info see the Rails Guide on Migrations or this slightly more in-depth post.