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
Creede Lambard
8,798 PointsStuck creating a user friendship - help!
I'm working on the code challenge for the "Finding and Building Models" part of the "Building Social Features in Ruby on Rails / Building The Friendship UI". I got the first two parts of the challenge right, but I'm stuck on the third. This is the code I've written:
class UserFriendshipsController < ApplicationController
def new
if params[:friend_id]
@friend = User.find(params[:friend_id])
@user_friendship = current_user.user_friendships.new(friend: @friend)
else
flash[:error] = "Friend required"
end
end
end
This code throws an error:
in `new': undefined method `user_friendships' for #<User:0x0000000164cb10 @options={:current_user=>true}> (NoMethodError)
I have to be missing something because (1) I cut and pasted the line in question directly from the zip file containing the project files, and (2) if I add a line saying "puts current_user.methods" just before the line in question, there's no hint of anything resembling user_friendships.
So, what am I missing?
Thanks,
-- Creede
5 Answers
Jason Seifer
Treehouse Guest TeacherHey Creede,
Your code is correct! We're fixing that code challenge right now. Try using the following to create the user friendship:
@user_friendship = UserFriendship.new(friend: @friend, user: current_user)
Sorry for the trouble!
Creede Lambard
8,798 PointsWhew! I'm not insane after all!! (Well, OK, I am insane, but it doesn't have anything to do with this bit of code.) Thanks for the quick reply Jason!
Yonatan Schultz
12,045 PointsSeem to still be having issues with this ( at least I am). I know the code is correct but after hitting 'Check Work' the system will stay stuck on 'Running'. I've tested across one Windows box as well as a mac machine. Although both running Chrome.
After typing that, I checked on OSX Firefox (19.0.2) and was able to get it to pass.
Jason Seifer
Treehouse Guest TeacherSorry for the issues, Yonatan. Occasionally the code challenges will time out. We're working on fixes for that.
Joy Scott
Courses Plus Student 10,660 PointsThis discussion was more than a year ago, but I'm still having issues. I've tried: @user_friendship = UserFriendship.new(friend: @friend, user: current_user) @user_friendship = UserFriendship.new(user: current_user, friend: @friend) and @user_friendship = current_user.user_friendships.new(friend: @friend)
None of which pass. Any ideas?
Thanks!
Joy Scott
Courses Plus Student 10,660 PointsWell, that was odd. I tried resubmitting the last one, and it took it. Sorry to bother.