Refile Gem Image Links Break When I Push a New Commit to Heroku
<p>My application is using the following gems:</p>

<pre><code>gem "refile", require: "refile/rails"
gem "refile-s3"
gem "refile-mini_magick"
</code></pre>

<p>What my application does is that it uploads image files to an AWS S3 instance, then gets retrieved using helper methods from the Refile gem.</p>

<p>Everything works as expected when I run it locally.</p>

<p><strong>The problem is when I push my app to Heroku, I can upload images and it displays correctly.  However, when I push a newer commit to Heroku, all previous images' links break.</strong></p>

<p>I've checked that the file_id of the image on the page is the same file_id of the image on the Heroku database.</p>

<p>This is my upload form for my images:</p>

<pre><code>  &lt;div class="field"&gt;
    &lt;%= f.label :images_files %&gt;&lt;br&gt;
    &lt;%= f.attachment_field :images_files, multiple: true, presigned: true, direct: true %&gt;
  &lt;/div&gt;
</code></pre>

<p>This is a snippet of my image being shown:</p>

<pre><code>&lt;%= attachment_image_tag(project.images.first, :file, :fill, 750, 400) %&gt;
</code></pre>

<p>I have set my environment variable correctly on Heroku so that it knows the keys to my AWS instance (access key id, secret access key, and bucket name).</p>

<p>This is the accessor to upload to S3:</p>

<pre><code># config/initializers/refile.rb
require "refile/s3"

aws = {
  access_key_id: ENV['AWS_ACCESS_KEY_ID'],
  secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
  region: "us-west-1",
  bucket: ENV['export S3_BUCKET'],
}

Refile.cache = Refile::S3.new(prefix: "cache", **aws)
Refile.store = Refile::S3.new(prefix: "store", **aws)
</code></pre>

<p>Another thing I've noticed was that my S3 bucket didn't hold the images in its correct folder if I uploaded through my Heroku app.  However, if I uploaded an image using the local server I can see the image in my S3 bucket.  I'm not sure why because all the environment variables are correct and I've double-checked it.</p>

<p>Here's a snippet of the Heroku log trying to load a picture:</p>

<pre><code>2016-01-12T23:04:39.448906+00:00 app[web.1]: Refile::App: Could not find attachment by id: d8fffa94c41f9f0ae1b233d69a75787a9a29340a9a83a831385d84d53ad8
2016-01-12T23:04:39.442789+00:00 heroku[router]: at=info method=GET path="/attachments/8718f3743b8d7c91e296ac5f0e6ea324d1fd2868/store/fit/800/475/aee08fe8f97269
826c51a77a11995c77467e24aa3581563d6f298e0dbf9b/file" host=www.domainname.com request_id=49edc34f-2d37-4ae4-9a58-e6265e00032e fwd="99.100.27.10" dyno=web.1 connect
=1ms service=9ms status=404 bytes=424
</code></pre>