Rails

Check If Item Has Attachment With Paperclip

Posted by Weston Ganger on July 07, 2014

Initially I was using:

if @post.image == ""

This will always return false with paperclip because the value will never be nil due the fact of the default_url missing.png

Instead you can check the following way:

if @post.image?

or

if @post.image.exists?

Posted in Rails and Tagged with paperclip rails 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts