sjain
sjain

Reputation: 23344

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.

Upvotes: 12

Views: 2417

Answers (2)

Alex Peattie
Alex Peattie

Reputation: 27647

The .exists? function optionally takes a style_name:

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

should work.

Upvotes: 31

Richlewis
Richlewis

Reputation: 15374

Try something like this

<% if @user.avatar(params[:large]) %><%= image_tag @user.avatar.url(:large), :id => "cropbox" %><% end %>

Upvotes: -2

Related Questions