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

Build a Simple Ruby on Rails Application Gravatar Help

Hi. I was working on this code challenge and was completely stumped on the final step. This is the video : http://teamtreehouse.com/library/build-a-simple-ruby-on-rails-application/deploying/adding-gravatars-2 and this is what it is asking : Update the gravatar_url method so it returns gravatr url, which takes the form http://gravatar.com/avatar/HASH where HASH is the hash you have just computed

This is what I put but it is not working. Please help.

class User < ActiveRecord::Base def gravatar_url self.email return http://gravatar.com/avatar/Digest::MD5.hexdigest(email.strip.downcase.strip) end end

3 Answers

I think you are missing a few lines. I passed with:

class User < ActiveRecord::Base

    def gravatar_url

        self.email

        email.downcase.strip

        hash = Digest::MD5.hexdigest(email.downcase.strip)

        return "http://gravatar.com/avatar/#{hash}"

    end

end

Sorry about the comment above; I didn't mean to post it twice... Maybe its easier to read here.

Simply the below works.

def gravatar_url
    hash = Digest::MD5.hexdigest(email.downcase.strip)

    return "http://gravatar.com/avatar/#{hash}"
end

Hi Ashkan! I struggled with this one myself :)

I think you simply overthought it. Instead of writing out the entire hash sequence in the url, you only have to put:

"http://gravatar.com/avatar/#{hash}"

For an explanation, rewatch the video starting at about 8:30.

Alyssa

Sorry for bothering you again but when I tried, it didn't seem to work. I'm not sure what I'm doing wrong. class User < ActiveRecord::Base def gravatar_url self.email return http://gravatar.com/avatar/#{hash} end end

It looks like you are missing a few lines. Here is what I passed with:

class User < ActiveRecord::Base
    def gravatar_url
        self.email
        email.downcase.strip
        hash = Digest::MD5.hexdigest(email.downcase.strip)
        return "http://gravatar.com/avatar/#{hash}"
    end
end

Thanks Alyssa. I appreciate it.