Skip to content

Instantly share code, notes, and snippets.

@BadAllOff
Forked from kinopyo/gist:2224867
Created November 10, 2016 08:57
Show Gist options
  • Save BadAllOff/3761d906d8cbd3adbce2c7fe86b4de9c to your computer and use it in GitHub Desktop.
Save BadAllOff/3761d906d8cbd3adbce2c7fe86b4de9c to your computer and use it in GitHub Desktop.
Check whether a Paperclip attachment exists

Check whether a Paperclip attachment exists

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 #photo? instead:

- if user.photo?
  = image_tag(user.photo.url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment