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 Deploying Adding Gravatars

David Langley
David Langley
10,965 Points

What value in the hash ?

Stuck on challenge 4 of 5 where you are supposed to add the hash;

my code

class User < ActiveRecord::Base def gravatar_url self.email.downcase.strip hash = Digest::MD5.hexdigest(self) end

end

I tried self thinking this is the only thing that references the email.... What am I missing ?

Thanks !

9 Answers

Tim Knight
Tim Knight
28,888 Points

David, you'll just be passing in the email method with the rest of the chain that you created in the previous tasks. It's basically:

class User < ActiveRecord::Base
  def gravatar_url
    Digest::MD5.hexdigest(email.downcase.strip)
  end
end
Tim Knight
Tim Knight
28,888 Points

You're welcome David, have fun with Ruby it's a blast!

David Langley
David Langley
10,965 Points

Hi Tim

sorry to come back to you on this challenge, I have only been learning ruby for the last week or so, therefore am still very green and asking silly questions.

in part 5 of the challenge i am having trouble determining what to put in the hash part of the URL.

The question is:

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

what I have now.\

def gravatar_url Digest::MD5.hexdigest(email.downcase.strip) http://gravatar.com/avatar/email.downcase.strip end

hope you can help.

Thanks Tim.

Tim Knight
Tim Knight
28,888 Points

David, you're so very close. The thing to remember is when you call the hexdigest method you're not actually changing your email method so you want to make sure you set a variable for that call. Then you should just be able to return a string with that variable interpellated into the string. So...

class User < ActiveRecord::Base
  def gravatar_url
    hash = Digest::MD5.hexdigest(email.downcase.strip)
    "http://gravatar.com/avatar/#{hash}"
  end
end
David Langley
David Langley
10,965 Points

Tim

That makes sense, most helpful again!

If you don't mind me asking, where did you learn ruby/rails, how long have you been doing it and are you a developer ?

I have to admit that ruby/rails is not coming to me as easy as some of the other languages I have done and overview of.

I am looking start developing web apps and mobile apps so hopefully Ruby/Rails starts to sink into my brain a little easier.

Thanks again your a star!

Tim Knight
Tim Knight
28,888 Points

Hi David,

I've been Ruby and Ruby on Rails now for about 6-7 years (roughly 2007-2008) and I am a Rails developer though I still focus on the general UX for the applications that I work on. I consider myself always learning (one of the reasons I'm here for example), so I'm always learning Ruby and Rails and will continue to do so. I think the biggest problem most newcomers have to the language and the framework is their adjustment to the mental model of how they look at web languages. If you have any background in basic PHP or even if it's just plain HTML that you've written, most people look at web sites as a group of pages that are being displayed in the browser. Rails is different. It's an application framework and the power that you have in the framework gives you incredible power when it comes to developing applications.

I learned Rails through books mostly because they didn't really have stuff like Treehouse while I was learning, but it took me a long time. If you haven't worked with JavaScript yet that might help you in working with variables and understanding how that works. Other than that just keep practicing... build apps that you're willing to delete in 30 minutes and just practice the basics over and over until your brain starts to see the power in the framework. It does happen and it is worth it.

You're welcome.

David Langley
David Langley
10,965 Points

Hi Tim,

Thanks for such a detailed and honest response, You are right with needing to get your head around the frame work is a big one, also just the complexity of having to set up the ruby/rails environment.

I am actually an architect in my other life and for years now has been interested in the world of tech and specifically mobile tech. Architecture in Australia is a very unstable industry so thought why not learn to code, better than sitting in front of the tv every night.

I have decided to put 12 months into it and see where it takes me.

Thanks again for answering my questions and any other advice you would have would be appreciated.

Thanks Tim, have a good week.

Tim Knight
Tim Knight
28,888 Points

You're doing great David, just keep going with it. Ruby is one of those languages that will change the way you think. A lot of people told that to me when I first started out and I thought they were crazy, but it's true.

Have a good week as well,

Tim