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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Andrew Martin](https://secure.gravatar.com/avatar/873ba0307d7b7d6ea1ead36418df562f?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Andrew Martin
17,513 PointsRuby Code Challenge : Scoped Finders
So this code challenge has been bugging me for a long time, a really long time, and frankly I admit I'm going to need some help, I clearly am missing something.
On the Scoped Finders challenge I've thrown three different 'answers' at the second part of this task to no avail, so any help would be muchly welcomed, very muchly.
EDIT: Oh man, I made this way more complicated then it actually was, I added in so much extras that I lost track of what the question was actually asking, I found my problem. Thanks.
Answer #1
class UserFriendshipsController < ApplicationController
before_filter :authenticate_user!
respond_to :html, :json
def index
case params[:list]
when nil
@user_friendships = current_user.pending_user_friendships.all
when 'blocked'
@user_friendships = current_user.blocked_user_friendships.all
end
respond_with @user_friendships
end
end
Answer #2
class UserFriendshipsController < ApplicationController
before_filter :authenticate_user!
respond_to :html, :json
def index
@user_friendships = UserFriendshipDecorator.decorate_collection(friendship_association.all)
respond_with @user_friendships
end
private
def friendship_association
case params[:list]
when nil
current_user.pending_user_friendships
when 'blocked'
current_user.blocked_user_friendships
end
end
end
Answer #3
class UserFriendshipsController < ApplicationController
before_filter :authenticate_user!
respond_to :html, :json
def index
if params[:list]
@user_friendships = current_user.blocked_user_friendships.all
else
@user_friendships = current_user.pending_user_friendships.all
end
end
end
2 Answers
![Andrew Martin](https://secure.gravatar.com/avatar/873ba0307d7b7d6ea1ead36418df562f?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Andrew Martin
17,513 PointsI've responded to your thread on this, in case anyone else ever encounters this hair-ripping dilemma, its here:
https://teamtreehouse.com/forum/issue-with-ruby-on-rails-code-challenge
![George Offley](https://secure.gravatar.com/avatar/c1db2d7011bf8823b6b5ba7d28cc3d03?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
George Offley
Courses Plus Student 7,386 PointsAny clues on the answer, because I've also been stuck on this for quite some time, and I'm tearing my hair out over it.
Any help would be greatly appreciated