回形针动态网址?

时间:2015-07-09 09:45:20

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

我有一个带有Paperclip image attachment列的Rails ActiveModel产品,需要从2个来源获取image.url。一个是旧的S3存储桶/ CloudFront,另一个是我们的新S3存储桶/ CloudFront。他们的凭据完全不同。

如果instance Product.image_file_name包含“old:”,我希望网址类似于cloudfront_url/products/file_name,如果不是,则应使用新的S3存储桶/ CloudFront。上传仅在新的S3存储桶上发生,但如果image_file_name包含old:正如我所提到的那样,它将在旧的存储桶上回退。

目前我只使用新的S3存储桶,而不是旧的存储桶。

我读过我应该做的事情:

    class Product
      has_attached_file: :image, url: dynamic_url_method

      def dynamic_url_method
         .... do some logic based on image_file_name
         return constructed_url
      end
    end

然而,当我这样做时,我得到未定义的局部变量dynamic_url_method。

如果我将其包裹在https://stackoverflow.com/a/10493048中所述的lambda中,我会得到Error "no implicit conversion of Proc into String"

你们有没有成功让Paperclip使用动态网址?如果你知道怎么做,这将是一个救生员。

0 个答案:

没有答案