views:

25

answers:

2

Hello, I just installed paper_clip to allow user's to upload a profile pic which can be displayed easily with:

<%= image_tag @user.profile_pic.url %>

What I'm curious about now is how to handle user's that don't have a profile_pic uploaded.. How to show a standard site user image (generic)

Should I make a helper?

something like showProfilePic(@user, size)

And then use that helper to show the right size image, either the user's uploaded photo or a generic site profile pic?

thanks. Any existing helpers out there?

+2  A: 

You can use the default_url and default_style options to set this. The default default_url is /:attachment/:style/missing.png, so you could drop in missing.png for each style and have that be your generic profile pic. If you want to customize, though...

class User < ActiveRecord::Base
  has_attached_file :profile_pic, 
    :default_style => :thumbnail,
    :default_url => '/path/to/:style_default.jpg'
end
Dave Pirotte
this worked very well. What about if I want to show a user's LARGE style, which isn't the default? How do I do <%= image_tag @user.profile_pic.url %>, but show LARGE, and if one doesn't exist, how to show a default per style?
AnApprentice
+1  A: 

In response to the question in your comment, check this out: http://stackoverflow.com/questions/3920349/paperclip-default-style-per-style-possible

Rafael Vega