Search code examples
ruby-on-railscontrollersposts

Rails acts_as_follower get posts of users I'm following AND my own


I've managed to scope my posts to just the users I'm following with the following code:

following_ids = current_member.following_members.map(&:id)
@statuses = Status.where(member_id: following_ids).order("created_at DESC")

But I want to also include my own posts and I'm having trouble accomplishing this. So basically combining that code with this code:

@statuses = @member.statuses.order('created_at desc').all

What's the best way to do this.


Solution

  • I figured this one out I needed to use push not flatten.

    @statuses = Status.where("member_id in (?)", following_ids.push(current_member.id)).order("created_at desc").all