Created
October 17, 2018 07:13
-
-
Save CaDs/f6c842e2e0d1ffdcf4b45432c6c0762a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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