2

I am using Paperclip for uploading the Profile image in my application (rails)

My User model is having a

 has_attached_file :avatar,
   :url => "/:attachment/:id/:style/:basename.:extension",
   :path => ":rails_root/public/:attachment/:id/:style/:basename.:extension",
   :styles => { :medium => "300x300>", :small => "100x100>", :thumb => "50x50>", :micro => "30x30>" }

In my VIew If i have a profile image uploaded then its pointing correctly as

/avatars/1/thumb/iamge

BUt if the image is not there if they didn't uploaded in that case its pointing as

/avatars/thumb/missing.png which doesn't have any image.

Please give suggestions what to do if the user didnt uploaded any profile image..

useranon
  • 29,318
  • 31
  • 98
  • 146
  • Do you have an image for `/avatars/thumb/missing.png`? This would be Paperclip's way of displaying a default image if the user didn't upload one. – Wukerplank Mar 10 '11 at 10:16
  • Possible duplicate of [Rails missing image](http://stackoverflow.com/questions/4253908/rails-missing-image) – Kick Buttowski May 19 '16 at 00:18

1 Answers1

3

You can make a default image and put it there and name it missing.png. It is like extra functionality :)

Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
Michael Koper
  • 9,586
  • 7
  • 45
  • 59
  • inside public/avatars i have created folder called thumb and an image for missing.png .. BUt i need to do the same for small -> missing and for all styles .. Is that a good way of doing . Or am i doing in a wrong way – useranon Mar 10 '11 at 10:21
  • That is the perfect way to do it. For every style image you want a missing image with another resolution. – Michael Koper Mar 10 '11 at 10:33
  • @MichaelKoper you can use some if conditions like if @user.avatar_file_name.blank?. I mean to say if their is no image uploaded then you did not need to show anything. – Ravindra Jul 07 '12 at 07:07