Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Brandon Barrette
Brandon Barrette
20,485 Points

Add default profile pic instead of Gravatar

So if you want to have your users have a default profile pic instead of using gravatar, you can change the following code:

def avatar_profile_link(user, image_options={}, html_options={})
    avatar_url = user.avatar? ? user.avatar.url : user.gravatar_url
    link_to(image_tag(avatar_url, image_options), profile_path(user.profile_name), html_options)
end

to this

def avatar_profile_link(user, image_options={}, html_options={})
    avatar_url = user.avatar? ? user.avatar.url : "avatardefault.png"
    link_to(image_tag(avatar_url, image_options), profile_path(user.profile_name), html_options)
end

Notice I just removed the gravatar path and added the file "avatardefualt.png". Put this default profile pic file in your assets/images folder and rails knows to look for it there.

1 Answer