diff --git a/app/controllers/api_users_controller.rb b/app/controllers/api_users_controller.rb index 86a7d3638..3b373fb28 100644 --- a/app/controllers/api_users_controller.rb +++ b/app/controllers/api_users_controller.rb @@ -48,21 +48,23 @@ class ApiUsersController < ApplicationController end def friend_request_update - @friend_request = FriendRequest.find(params[:id]) - @friend_request.accepted = params[:accepted] - @friend_request.save + ActiveRecord::Base.transaction do + @friend_request = FriendRequest.find(params[:id]) + @friend_request.accepted = params[:accepted] + @friend_request.save - # create both records for this friendship - if @friend_request.accepted? - @friendship = Friendship.new() - @friendship.user_id = @friend_request.user_id - @friendship.friend_id = @friend_request.friend_id - @friendship.save + # create both records for this friendship + if @friend_request.accepted? + @friendship = Friendship.new() + @friendship.user_id = @friend_request.user_id + @friendship.friend_id = @friend_request.friend_id + @friendship.save - @friendship = Friendship.new() - @friendship.user_id = @friend_request.friend_id - @friendship.friend_id = @friend_request.user_id - @friendship.save + @friendship = Friendship.new() + @friendship.user_id = @friend_request.friend_id + @friendship.friend_id = @friend_request.user_id + @friendship.save + end end respond_with @friend_request, responder: ApiResponder