Check whether a Paperclip attachment exists

Posted Almost 13 years ago. Visible to the public.

Don't simply test for the presence of the magic Paperclip attribute, it will return a paperclip Attachment object and thus always be true:

- if user.photo.present? # always true
  = image_tag(user.photo.url)

Use #exists? instead:

- if user.photo.exists?
  = image_tag(user.photo.url)
Henning Koch
Last edit
Almost 12 years ago
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2011-07-28 16:15)