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 trialAshley Schneider
7,627 PointsAdding Gravatars Code Challenge
The first code challenge asks you to "Add a method to User called gravatar_url. This method should for now simply return the email address, which should be retrieved using the email method on User."
I've tried everything! I have no clue what to put to pass this code challenge. I thought I was on the right track with putting <%= status.user.gravatar_url %> but that was wrong.
6 Answers
Philipp Antar
7,216 PointsThe challenge takes place in the User model, not in a view. Therefore you won't need these ERB tags: <%= %>
. The User model is pure ruby code and it describes the User class. You're asked to add a method to this class and this method should return the email of an instance of the User class. You can achieve this by using the self
keyword in the method body:
class User < ActiveRecord::Base
def gravatar_url
self.email
end
end
BTW -- Ruby features an implicit return of the last evalued expression, hence there's no need for the return
keyword.
HTH :)
Marin Gerov
28,501 PointsHi guys,
What also works is
class User < ActiveRecord::Base
def gravatar_url
email
end
end
Ashley Schneider
7,627 Pointsthank you so much! this totally helped!
Yaron Attar
9,738 Pointsthank you.
Neill dev
Courses Plus Student 23,163 PointsYes, thank you Philipp...but can anyone explain why user.email or User.email would not work...self.email (Which I assume is similar to 'this' in JS) was not addressed in the video, therefore I don't think this was the expected answer? Rdgs Neill
Philipp Antar
7,216 Pointsuser.email
would refer to an object of class User, which has a method called email
. User.email
refers to a class User
having a class-method email
. What we want, however, is to provider an instance method for instances of the class User. Read about the differences between class, instances of classes, class methods and instance methods. I'm sure it will quickly make sense.