Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining Image presence and absence that has certain style - Paperclip rails

Is there a way to determine the existence of a given image style?

For example to determine whether the image exists at all, we can do:

    <% if @user.avatar.exists? %>
      <%= image_tag @user.avatar.url(:large), :id => "cropbox" %>  

But how can we determine whether the image exists in a particular style, say for instance thumb?. The above condition only determines the existence of an image in its original style.

like image 478
My God Avatar asked Dec 06 '12 15:12

My God


1 Answers

The .exists? function optionally takes a style_name:

<% if @user.avatar.exists?(:large) %>

should work.

like image 160
Alex Peattie Avatar answered Oct 23 '22 01:10

Alex Peattie