2

I am using s3 with Paperclip which is working well. I am running into problems however with the default_url for missing attachements. I want the default_url to be :attachement/default/:style in the same s3 bucket as the other files. However the default_url when used to generate a missing image is local for the rails app which is not what I want. E.g

/avatar/default/thumb is not what I want for the default, instead I want {s3_base_url}/avatar/default/thumb. I cannot figure out how to do this.

Hugo Tunius
  • 2,869
  • 24
  • 32
  • have you tried to replace the missing images using javascript? that can point to your s3 image url... check this out: http://stackoverflow.com/questions/92720/jquery-javascript-to-replace-broken-images – Mavis Jul 02 '14 at 13:03
  • This is for a REST API so no javascript available. I solved it, but I am not really satisfied with the result. I'll post my answer though – Hugo Tunius Jul 02 '14 at 14:00

1 Answers1

4

So I solved it, but I am not overly pleased with the solution.

initializers/paperclip.rb Paperclip.interpolates(:s3_bucket) do |attachement, style| Rails.application.config.paperclip_defaults[:s3_credentials][:bucket] end

Model

default_url: "http://:s3_bucket.s3.amazonaws.com/avatar/default/:style

It would of course be possible to add a fuller interpolation with the complete path to s3, but this is a workable solution.

Hugo Tunius
  • 2,869
  • 24
  • 32