wrap friend creation in transaction

This commit is contained in:
Brian Smith 2012-10-24 20:18:26 -04:00
parent 5e2bac6e95
commit db21a70190
1 changed files with 15 additions and 13 deletions

View File

@ -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