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
Steve McKinney
29,274 PointsHaving trouble on the managing friendships > creating model methods test
I'm not sure where I'm going wrong, as it should be what's shown in the video.
Question
Make the has_blocked? method check to see if the user passed in is included in the list of blocked friends.
My code
class User < ActiveRecord::Base
has_many :user_friendships
has_many :friends, through: :user_friendships
has_many :pending_user_friendships, class_name: 'UserFriendship', conditions: { state: 'pending' }
has_many :blocked_user_friendships, class_name: 'UserFriendship', conditions: { state: 'blocked' }
has_many :pending_friends, through: :pending_user_friendships
has_many :blocked_friends, through: :blocked_user_friendships
# write your code here
def has_blocked?(other_user)
blocked_friends.include?(other_user)
end
end
Where am I going wrong? Thanks in advance for your help!
Steve McKinney
29,274 PointsI've tried to see if there was a way something like that could be included but it doesn't work. It says either test one doesn't pass or the doesn't respond to the has_blocked? method. I have gone over the video a few times to see if anything else makes sense but this is the exact code of the video.
Marwa zada
UX Design Techdegree Student 15,460 PointsI'm having trouble with this as well. Have you guys been able to figure it out?
I really can't think of any other way this should be written out other than
def has_blocked?(other_user)
blocked_friends.include?(other_user)
end
Steve McKinney
29,274 PointsI'm still stuck with this. I've just continued on to the next stage. It definitely is that code as it's exactly that in the video.
4 Answers
Jon Gjerset
3,816 PointsFound a solution by adding the source: :friend to the end of the blocked_friends relationship
has_many :blocked_friends, through: :blocked_user_friendships, source: :friend
Jason Seifer
Treehouse Guest TeacherThis is now fixed in the code challenge itself. Sorry for the trouble and thanks everyone!
Marwa zada
UX Design Techdegree Student 15,460 PointsJon Gjersets solution works
Jon Gjerset
3,816 PointsSame problem here.
Naomi Freeman
Treehouse Guest TeacherNaomi Freeman
Treehouse Guest TeacherHaven't gotten this far yet. But have you defined other_user somewhere? And if it's defined somewhere outside of the thing you're working inside of, do you need an @ or # or : or anything? Just first thoughts.