[Rails] paperclip圖片是否存在判斷
原本使用
<% if user.photo.present? %> # 總是ture
<%= image_tag(user.photo.url) %>
<% end %>
改使用exists判斷
<% if user.photo.exists? %>
<%= image_tag(user.photo.url) %>
<% end %>
參考
- https://makandracards.com/makandra/1419-check-whether-a-paperclip-attachment-exists
留言