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

Ruby Building Social Features in Ruby on Rails Creating Friendships Testing Friendships

Treebook - Friend_id not saving?

Hey everyone! Im doing the rails project on Building Social Features. I'm trying to create the "Add Friends" feature but it seems that when I click the button it won't save the friend_id. Any suggestions?

2 Answers

I think you might need where instead of find. e.g.

def new
  if params[:friend_id]
    @friend = User.where(params[:friend_id])
    @user_friendship = current_user.user_friendship.new(friend: @friend)
  else
    flash[:error] = "Friend Required"
  end
end

What error are you getting and does it reference a line of code?