1

I've just upgraded from Rails 3.1 to Rails 3.2.6 and my paperclip photo paths are now broken on production.

photo.rb

if Rails.env == "production"
  has_attached_file :image,
    :storage => :s3,
    :s3_credentials => S3_CREDENTIALS,
    :url => "/app/public/system/images/:id/:style/:basename.:extension",

I need the resulting path to be like so: http://s3.amazonaws.com/photoramblr/app/public/system/images/5/thumb_large/image.jpg

but instead the above url settings result in: http://s3.amazonaws.com/photoramblr/app/public/app/public/system/images/5/thumb_large/image.jpg

I've also tried setting the paperclip url to :url => "/system/images/:id/:style/:basename.:extension" but that resulted in this url: http://s3.amazonaws.com/photoramblr/images/5/thumb_large/image.jpg

Any thoughts on how I can set this properly?

UPDATE: Well, I still don't understand how it's working, but I 'fixed' this by just moving the files to the location it was looking in.

4

1 回答 1

1

尝试添加一个路径参数来替换 url 参数,并在存储桶名称下指定存储文件的路径,并且 URL 将从存储桶和提供的路径构造。这是 回形针 s3 文档的链接以获取更多详细信息。如果您提供一个 url 参数,它会被视为相对于您的“应用程序/公共”。这就解释了为什么你得到的图像路径加倍“app/public”。Ryan Bate 的回形针教程也解释了这种行为。在您的情况下,您的代码将如下所示;

if Rails.env.production?
  has_attached_file :image,
    :storage => :s3,
    :s3_credentials => S3_CREDENTIALS,
    :path => "app/public/system/images/:id/:style/:basename.:extension",

您生成的链接将是(我假设您的存储桶名称是链接中的 photorambler);s3.amazonaws.com/photorambler/app/public/system/images/5/thumb_large/image.jpg

于 2012-07-16T11:42:25.687 回答