Reputation: 23344
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
Reputation: 27647
The .exists?
function optionally takes a style_name:
<% if @user.avatar.exists?(:large) %>
should work.
Upvotes: 31
Reputation: 15374
Try something like this
<% if @user.avatar(params[:large]) %><%= image_tag @user.avatar.url(:large), :id => "cropbox" %><% end %>
Upvotes: -2