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

Implementing 'Twitter like' Follow instead of Friend Requests

I've been following the tutorials for creating Treebook. However, rather than implementing friend requests, pending friends, etc. I'm working on a basic follower/following model. I've been running into issues with my Create method in my User friendship controller. Namely, the 'Follow' button in my app does not perform as expected. Does anyone notice any glaring issues with my Create method?

def create if params[:user_friendship] && params[:user_friendship].has_key?(:friend_id) @friend = User.where(profile_name: params[:user_friendship][:friend_id]).first @user_friendship = current_user.user_friendships.new(friend: @friend) respond_to do |format| if @user_friendship.new_record? format.html do flash[:error] = "There was a problem with following." redirect_to profile_path(@friend) end format.json {render json: user_friendship.to_json, status: :precondition_failed } else format.html do flash[:success] = "You are now following #{@friend.full_name}" redirect_to profile_path(@friend) end format.json {render json: user_friendship.to_json } end end else flash[:error] = "Friend required" redirect_to root_path end end