Skip to content

Instantly share code, notes, and snippets.

@ajsharp
Created August 23, 2009 00:31
Show Gist options
  • Save ajsharp/173063 to your computer and use it in GitHub Desktop.
Save ajsharp/173063 to your computer and use it in GitHub Desktop.
def make_friends(user, target)
transaction do
begin
Friend.find(:first, :conditions => {:inviter_id => user.id, :invited_id => target.id, :status => PENDING}).update_attribute(:status, ACCEPTED)
Friend.create!(:inviter_id => target.id, :invited_id => user.id, :status => ACCEPTED)
rescue Exception
return make_friends( target, user) if user.followed_by? target
return add_follower(user, target)
end
end
true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment