$ rails generate model AttachmentImage attachable_id:integer attachable_type:string
class CreateAttachmentImage < ActiveRecord::Migration
def self.up
create_table :attachment_images do |t|
t.integer :attachable_id
t.string :attachable_type
t.timestamps
end
end
class AttachmentImage < ActiveRecord::Base
belongs_to :attachable, polymorphic: true
end
class Blog < ActiveRecord::Base
has_many :entries
has_one :attachment_image, as: :attachable
end
class Entry < ActiveRecord::Base
belongs_to :blog
end
def self.down
drop_table :attachment_images
end