In my application I have the option for a user to upload an image for a profile picture through paperclip.
Want I want to do in the index.html.erb page is to display all users with their display pictures, and if they have not uploaded one then it should display a default picture.
Now I have tried coding it in but at the moment the users who have pictures have the displayed but those who don’t get nothing.
I have the following code in my user model:
def user_photo
(photo.url.present?) ? photo.url : '/images/guest.png'
end
and the following code in my index.html.erb
<% for user in @users %>
.............
<%= image_tag user.user_photo, :height => 50, :width => 50 %>
..............
<% end %>
Any ideas on what my problem might be?
Thanks
Have something like this in your user model:
The :default_url option is used if there is no attached file for a model. If a user doesn’t have any uploaded photo you could use this option to set a default photo to show.
In the view:
Read Paperclip usage guide