Paperclip works fine when I upload an image and then display it with:
<%= image_tag @post.photo.url(:medium) %>
The problem is, if an image wasn't uploaded, I get this error:
NoMethodError in Posts#show
Showing /Users/me/RubymineProjects/level_60/app/views/posts/show.html.erb where line #16 raised:
undefined method `[]' for nil:NilClass
I try to check and see if the image exists with <% if @post.photo %>
or <% if @post.photo != '' %>
. However, both of those always return true even when there's no image uploaded.
How do I display an image through paperclip only if it exists?