【问题标题】:Paperclip: Product with multiple Attachments回形针:带有多个附件的产品
【发布时间】:2013-01-31 16:48:17
【问题描述】:

我有一个如下所示的产品模型:

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

还有一个像这样的图像模型

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

将图像从 url 保存到 s3 的最简单方法是什么?我可以使用 Product 模型中的 :ean 值作为 s3 路径吗?

【问题讨论】:

    标签: ruby-on-rails amazon-s3 paperclip


    【解决方案1】:

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

    然后您只需定义推送到 s3 函数

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多