0

I have a Product model that looks like this:

class Product < ActiveRecord::Base
  attr_accessible   :name_en, :ean
  has_many   :images, :dependent => :destroy
end

and an Images model that looks like this

class Images < ActiveRecord::Base
  attr_accessible :image, :product_id, :source
  has_attached_file :image, :styles => { :medium => "150x150>" },
                                        :storage => :s3,
                                        :s3_credentials => "#{Rails.root}/config/s3.yml",
                                        :bucket => "test",
                                        :path => "/products/:ean/:style.:extension";
  belongs_to :product
end

What is the easiest way to save images from an url to s3 and can I use the :ean value from the Product model for the s3 path?

4

1 回答 1

0

使用活动记录回调..... before_save :push_to_s3 或 after_save :push_to_s3

然后您只需定义推送到 s3 功能

于 2013-01-31T22:24:53.570 回答