what does the followed_by construct mean?

D

Dan Quach

I'm reading some code and it states..

#this can only occur on the person who was invited
def make_friends(invited, inviter)
transaction do
if user.followed_by? target


what does user.followed_by mean?

thanks!
-dan
 
P

Phillip Gawlowski

I'm reading some code and it states..

#this can only occur on the person who was invited
def make_friends(invited, inviter)
transaction do
if user.followed_by? target


what does user.followed_by mean?

The code snippet you provided is far too short to tell you for sure.

A rough guess would be that #followed_by? checks if the target follows
the user described in the user object.

If you could provide more detail, it'd be appreciated. :)
 
D

Dan Quach

Phillip said:
The code snippet you provided is far too short to tell you for sure.

A rough guess would be that #followed_by? checks if the target follows
the user described in the user object.

If you could provide more detail, it'd be appreciated. :)

Sorry bout that.. heres the full snippet
#this can only occur on the person who was invited
def make_friends(invited, inviter)
transaction do
if user.followed_by? target

#update the existing pending relationship of 2 --> 1
Friend.find:)first, :conditions => {:inviter_id => inviter.id,
:invited_id => invited.id, :status =>
PENDING}).update_attribute:)status, ACCEPTED)

#create the relationship of 1 --> 2
Friend.create!:)inviter_id => inviter.id, :invited_id =>
invited.id, :status => ACCEPTED)
else
return add_follower(user, target)unless user.following? target
end
end
true
end
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

First, there is a board specific to rails, try
http://lists.rubyonrails.org/mailman/listinfo/rails

Here are my thoughts, though, and please understand that I cannot see your
application, so I am simply hypothesizing.

Also, the method is presumably defined in app/models/user.rb and examining
that method would shed more information.



Based on the context, my assumptions would be:

You have two users, that are using the site in some way.
One user may see how another user is using the site, and finds it
interesting (she has a cute screenname).
He decides to follow her, which invokes the 'make_friends' method.

At this point, he is the user and she is the target. She is not following
him (she's a cold mamba jamba), so it returns false. Which causes your code
to add him as a follower to her, unless he is already following her (stalker
alert). This creates a row in the friends table that has him as the inviter,
and her as the invited. But she hasn't accepted yet, so it sets the status
column to PENDING.
For more info on how this is done, see
http://guides.rubyonrails.org/association_basics.html#self-joins or look at
your Friend model.

She receives the friend request, and decides he is interesting (has a sexy
avatar) So she accepts the friend request, or just goes to his
app/views/users/show.html.erb and follows him.

This invokes the 'make_friends' method, this time with her as the user, and
him as the target. Since he sent her a friend request earlier,
user.followed_by?(target) returns true. It then finds that request, and
updates status to ACCEPTED and also creates another record, with her as the
inviter, him as the invited, and status ACCEPTED, so there are two records,
one from him to her, and one from her to him.

Your code apparently considers this to be friendship (heartwarming).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,840
Latest member
BrendanG78

Latest Threads

Top