Syncronization in rails

Hello,

Here is the logic that I am trying to achieve. I have a User Model and
the business rule is that user can accept maximum 5 friends requests.

for this I have an accept method in User Model which looks similar to
below code snippet

def accept(friend)
    raise ArgumentError if self.friends.count >= MAX_FRIENDS_ALLOWED
    ...
    ...
    #code to add friend to friends list
end
As you can see that I basically query for count of friends for a user
and if the count is greater then or equal to MAX_FRIENDS_ALLOWED the
friend accept request should not go through.

From the UI perspective I have a link_to_remote, "Accept" link that
calls an action which calls the User Model's "accept" method. Basically
UI looks like

FRIEND NAME | Action

http://api.rubyonrails.org/classes/ActiveRecord/Locking/Pessimistic.html