Skip to content

Instantly share code, notes, and snippets.

@CaDs
Created October 17, 2018 07:13
Show Gist options
  • Save CaDs/f6c842e2e0d1ffdcf4b45432c6c0762a to your computer and use it in GitHub Desktop.
Save CaDs/f6c842e2e0d1ffdcf4b45432c6c0762a to your computer and use it in GitHub Desktop.
class PostsController < ApplicationController
before_action :auth_user
def index
@posts = @user.fetch_feed
end
end
class User < ApplicationRecord
def fetch_feed
Post.eager_load(:user)
.where(user: self.following + [self])
.order('posts.created_at DESC')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment