Wesly Wesly - 7 months ago 10
Ruby Question

How to display the current_user posst plus the people that user follows?

I want to display my posts and the people who i'm following as well.
I Tried doing

@posts = Post.where(user_id: current_user.following_users.ids)
and it only shows the posts of the people i follow. What would be the best way to show my posts in the feed?

UsersController


def following
@user = User.find params[:id]
current_user.mark_as_following @user
redirect_to @user
end


HomeController


def show
@posts = Post.where(user_id: current_user.following_users.ids)
end

Answer

You could solve it by just adding the current user id to the scope like this

def show
  @posts = Post.where(user_id: current_user.following_users.ids + [current_user.id])
end