Database Reference
In-Depth Information
To display the list of the users the current user is following, the /
friends
route, showing in Listing 10-25, in the
App
class calls the
following
method in the
User
class.
Listing 10-25.
The
/friends
Route
# friends route that shows connected users via FOLLOW relationship
get '/friends' do
@title = "Friends"
@following = following(neo, request.cookies[graphstoryUserAuthKey])
mustache :"graphs/social/friends"
end
The method shown in Listing 10-26 creates a list of users by matching the current user's username with directed
relationship FOLLOWS on the variable user.
Listing 10-26.
The
following
Method in the
User
Class
def following(neo,username)
cypher = " MATCH (user { username:{u}})-[:FOLLOWS]->(users) "+
" RETURN users.firstname as firstname, users.lastname as lastname, " +
" users.username as username " +
" ORDER BY users.username"
results = neo.execute_query(cypher, u: username})
results["data"].map {|row| Hash[*results["columns"].zip(row).flatten] }
end
If the list contains users, it will be returned to the controller and displayed in the right-hand part of the page, as
shown in Figure
10-9
. The display code for showing the list of users can be found in
{PROJECTROOT}/ app/views/
graphs/social/friends.mustache
and is shown in the code snippet in Listing 10-27.
Figure 10-9.
The Friends page