Você pode fazer o seguinte crie um migrate como este
class CreatePhotos < ActiveRecord::Migration
def self.up
create_table :photos do |t|
t.string :name
t.references :imageable, :polymorphic => true
t.timestamps
end
end
def self.down
drop_table :photos
end
end
e depois você adicione o seguinte no model photo.rb
class Photo < ActiveRecord::Base
belongs_to :imageable, :polymorphic => true
end
Agora em qualquer model você pode adicionar o has_many
class Product < ActiveRecord::Base
has_many :photos, :as => :imageable
...
end
@product.photos << Photo.new({:name => "test"})
E isso ai...
Abs,
R.