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 trialAndrew 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
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
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