0

I have this piece of code that doesn't seem to work for a strange reason:

    <% if (@user.photo.blank?) %>               
        <%= image_tag("empty_profile_pic.png") %> <!-- replace with user's image -->
    <%else %>
        <%= image_tag(@user.photo.url(:small)) %> 
    <% end %>

If the picture is null in the mySQL database I want it to display another pic. I have tried, empty?, nil?, blank? but with no success, and also

 @user.photo.blank.url.*

Any help?

1
  • What plugin do you use for image-handling? Carrierwave? Dragonfly? Paperclip? Commented Jun 8, 2012 at 11:11

2 Answers 2

1

How about

@user.photo.exists?

~Charles~

Sign up to request clarification or add additional context in comments.

Comments

1
<%= image_tag(@user.photo.try(:url, :small) || "empty_profile_pic.png") %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.