0

I had to reconfigure my uploader. I'm using carrierwave and minimagick. So in a nutshell, I had images automatically processed/resized when they were initially uploaded before. Now I don't want them automatically processed, I'm keeping the original size and creating a version named normal for the resized image.

Now some images that are uploaded will have the normal version. But images that were uploaded prior to the reconfiguration won't. To avoid broken images, I've created a conditional that works great in development.

  <% if car.picture_attachments.first.picture.normal.present? %>
        <%= image_tag(car.picture_attachments.first.picture.normal.url) %>
      <% else %>
        <%= image_tag(car.picture_attachments.first.picture) %>
      <% end %> 

But in Heroku - it thinks every object has a normal version and is serving a bunch of broken images as a result. I'm using Amazon S3 - any clue why this is happening?

dgreen22
  • 388
  • 4
  • 19

1 Answers1

0

Had to use this:

<% if car.picture_attachments.first.picture.normal.file.exists? %>

difference between present? and exists? is important. See difference here: https://stackoverflow.com/a/13186788/5551783

Note exists? is far slower than present? because it checks the database for each instance.

dgreen22
  • 388
  • 4
  • 19