2 thoughts on “Rails social layer”

  1. The other commenter is right that your request is a bit ambiguous, but I’ll do my best based on what I’ve got. :).

    Here’s how I’d approach building those features:

    I’ll assume you have db table for users that includes like their userID, name, email, hashed password, Url, bio or whatever…and maybe an array that includes a list of IDs in another table for their posts….and the ability to look up posts by userID in a “posts” table

    Put a database column in the users table called “friends” that stores an array of userIDS for friends.

    When the user clicks the add friend button it should check that friends array to ensure the USERID you want to add doesn’t exist and if it doesn’t, you add them. (This gets more complicated if you want a system of requests and confirmations first, but build the basic version first). When you render a users page you loop through their friend array to populate their friends list

    It’s basically the same for a block list. Store the userIDs of all the users blocked users in an array in the users table, and check if it exists when you need to check if a person is blocked.

    Obviously (or maybe not so obviously if you’re just starting out) you need a list of times when it should make these checks, and some tests to ensure those checks are functioning properly.)

    Liking stuff is kind of the same. If a person likes a post it should probably put their userID in an array that keeps track of the likes…probably in the table that contains the post itself, as likes more logically belong to the post than the user…(arguably) and then when you render the post you can loop that array and use the info from it to populate the list of who liked the post.

    Of course if they are blocked, the like should not be rendered, so you need some sort of if clause in that loop that calls up all the likes which skips if it finds the like is from a USERID that currently exists in the post author or viewers blocked list.

    Hopefully that answers the question you’re asking. Basically you want to think of what type of data you need, how to get it, how best to store it in the database, how best to retrieve it, and when to do so, and any gotchas you might be run into, like attempting to add a friend who already has you blocked.


Leave a Comment