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 trialRachel Bird
11,968 PointsCoding challenge broken: Finding and Building Models 2&3/3
I'm in the Building the Friendship UI badge of Building Social Features in Ruby on Rails. Yesterday I couldn't get past the third challenge, and today it's stuck on the second. Could someone at Treehouse please fix it? I've finished the course and am just stuck on this.
Thank you!
class UserFriendshipsController < ApplicationController
def new
if !params[:friend_id] #passes on first challenge
@friend = User.find(params[:friend_id] #same as on video
flash[:error] = "Boo" # Write your code here
end
end
end
Isn't passing for 2/2.
3 Answers
Gloria Dwomoh
13,116 PointsFirst of all let me note you forgot a parenthesis at the end of the find statement. Secondly you want to flash an error if there is no friend id parameter BUT if there is a friend with the id parameter you want to find it, therefore you need an else statement as the if checks if there is not a friend with the id parameter. So you have to find the friend in the else statement, after doing that you should end up with a functional code that looks like this:
class UserFriendshipsController < ApplicationController
def new
if !params[:friend_id] #passes on first challenge
flash[:error] = "Boo" # Write your code here
else
@friend = User.find(params[:friend_id]) #same as on video
end
end
end
Rachel Bird
11,968 PointsI'll change it then. Equivocated with Rails Development. Thanks.
Gloria Dwomoh
13,116 PointsAwesome!
Rachel Bird
11,968 PointsFor some reason, I needed your to provide clarity so I could get through this! Once that was sorted, I passed the next one as well. Many thanks! :)
Gloria Dwomoh
13,116 PointsYou are welcome :)
Gloria Dwomoh
13,116 PointsGloria Dwomoh
13,116 PointsThis question seems to be related to Ruby and not about Development Tools, right? I suggest you change the Tag to Ruby and also link the challenge, that way people that know Ruby on Rails might be able help. It's hard to help without knowing what the question is.