-
-
Save ahmadhasankhan/9427f50ba87e2b4835c2ebe848911564 to your computer and use it in GitHub Desktop.
Revisions
-
ahmadhasankhan revised this gist
Nov 26, 2017 . 8 changed files with 912 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ class User < ApplicationRecord has_many :posts has_many :comments # id :integer not null, primary key # name :string(50) default("") end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,4 +6,17 @@ class Post < ApplicationRecord # user_id :integer # content :text default("") # created_at :datetime DEFAULT_PAGE_LIMIT = 50 # By default fetching records in descending order, however, we can always override the default scope using unscoped method default_scope -> { order(created_at: :desc) } # We can reuse this anywhere and pass the different limit as per the need, By default limit is 50 scope :most_recent, ->(limit = DEFAULT_PAGE_LIMIT) { preload_conditions.limit(limit) } # This will preload related objects when you include it in the query def self.preload_conditions includes(:user, comments: [:user]) end end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,4 +5,7 @@ class NewsfeedController < ApplicationController # will also include the User object of the Comment's author. # TODO: Newsfeed endpoint here def index @news_feeds = Post.most_recent.paginate(page: params[:page], per_page: 50) end end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ json.comments comments do |comment| json.type comment.class.name json.partial! 'newsfeed/user', user: comment.user json.content comment.content end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ json.type post.class.name json.content post.content json.partial! 'newsfeed/user', user: post.user json.partial! 'newsfeed/comment', comments: post.comments This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ json.user do json.type user.class.name json.name user.name end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ json.array! @news_feeds, partial: 'newsfeed/feed', as: :post This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,881 @@ [ { "type": "Post", "content": "using loop 50", "user": { "type": "User", "name": "ahmad" }, "comments": [] }, { "type": "Post", "content": "using loop 49", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 56" } ] }, { "type": "Post", "content": "using loop 48", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 54" }, { "type": "Comment", "user": { "type": "User", "name": "Hassan" }, "content": "This is comment 55" } ] }, { "type": "Post", "content": "using loop 47", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 51" }, { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 52" }, { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 53" } ] }, { "type": "Post", "content": "using loop 46", "user": { "type": "User", "name": "ahmad" }, "comments": [] }, { "type": "Post", "content": "using loop 45", "user": { "type": "User", "name": "ahmad" }, "comments": [] }, { "type": "Post", "content": "using loop 44", "user": { "type": "User", "name": "ahmad" }, "comments": [] }, { "type": "Post", "content": "using loop 43", "user": { "type": "User", "name": "ahmad" }, "comments": [] }, { "type": "Post", "content": "using loop 41", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 49" } ] }, { "type": "Post", "content": "using loop 42", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "Hassan" }, "content": "This is comment 50" } ] }, { "type": "Post", "content": "using loop 0", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 8" } ] }, { "type": "Post", "content": "using loop 1", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 9" } ] }, { "type": "Post", "content": "using loop 2", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 10" } ] }, { "type": "Post", "content": "using loop 3", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 11" } ] }, { "type": "Post", "content": "using loop 4", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 12" } ] }, { "type": "Post", "content": "using loop 5", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 13" } ] }, { "type": "Post", "content": "using loop 6", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 14" } ] }, { "type": "Post", "content": "using loop 7", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 15" } ] }, { "type": "Post", "content": "using loop 8", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 16" } ] }, { "type": "Post", "content": "using loop 9", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 17" } ] }, { "type": "Post", "content": "using loop 10", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 18" } ] }, { "type": "Post", "content": "using loop 11", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 19" } ] }, { "type": "Post", "content": "using loop 12", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 20" } ] }, { "type": "Post", "content": "using loop 13", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 21" } ] }, { "type": "Post", "content": "using loop 14", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 22" } ] }, { "type": "Post", "content": "using loop 15", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 23" } ] }, { "type": "Post", "content": "using loop 16", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 24" } ] }, { "type": "Post", "content": "using loop 17", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 25" } ] }, { "type": "Post", "content": "using loop 18", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 26" } ] }, { "type": "Post", "content": "using loop 19", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 27" } ] }, { "type": "Post", "content": "using loop 20", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 28" } ] }, { "type": "Post", "content": "using loop 21", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 29" } ] }, { "type": "Post", "content": "using loop 22", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 30" } ] }, { "type": "Post", "content": "using loop 23", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 31" } ] }, { "type": "Post", "content": "using loop 24", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 32" } ] }, { "type": "Post", "content": "using loop 25", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 33" } ] }, { "type": "Post", "content": "using loop 26", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 34" } ] }, { "type": "Post", "content": "using loop 27", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "Hassan" }, "content": "This is comment 35" } ] }, { "type": "Post", "content": "using loop 28", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 36" } ] }, { "type": "Post", "content": "using loop 29", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 37" } ] }, { "type": "Post", "content": "using loop 30", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "Hassan" }, "content": "This is comment 38" } ] }, { "type": "Post", "content": "using loop 31", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 39" } ] }, { "type": "Post", "content": "using loop 32", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 40" } ] }, { "type": "Post", "content": "using loop 33", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 41" } ] }, { "type": "Post", "content": "using loop 34", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 42" } ] }, { "type": "Post", "content": "using loop 35", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "Hassan" }, "content": "This is comment 43" } ] }, { "type": "Post", "content": "using loop 36", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 44" } ] }, { "type": "Post", "content": "using loop 37", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 45" } ] }, { "type": "Post", "content": "using loop 38", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "Hassan" }, "content": "This is comment 46" } ] }, { "type": "Post", "content": "using loop 39", "user": { "type": "User", "name": "ahmad" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "ahmad" }, "content": "This is comment 47" } ] } ] -
Jimmie Tyrrell revised this gist
Jul 27, 2017 . 2 changed files with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ class User < ApplicationRecord has_many :posts has_many :comments # id :integer not null, primary key # name :string(50) default("") end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ class Post < ApplicationRecord belongs_to :user has_many :comments # id :integer not null, primary key # user_id :integer -
Jimmie Tyrrell revised this gist
Jun 9, 2017 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,39 +1,51 @@ [ { "type": "Post", "content": "First post", "user": { "type": "User", "name": "Luke" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "Leia" }, "content": "First comment" }, { "type": "Comment", "user": { "type": "User", "name": "Han" }, "content": "Second comment" }, ] }, { "type": "Post", "content": "Second post", "user": { "type": "User", "name": "Darth Vader" }, "comments": [ { "type": "Comment", "user": { "type": "User", "name": "Boba Fett" }, "content": "Third comment" }, { "type": "Comment", "user": { "type": "User", "name": "Jabba" }, "content": "Fourth comment" -
Jimmie Tyrrell revised this gist
May 30, 2017 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,8 @@ class NewsfeedController < ApplicationController # JSON endpoint that returns an array of Post objects in order of # newest first, to oldest last. Each Post contains a User object # (the author of the Post), and an array of Comments. Each Comment # will also include the User object of the Comment's author. # TODO: Newsfeed endpoint here end -
Jimmie Tyrrell revised this gist
May 30, 2017 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,6 @@ class Post < ApplicationRecord # id :integer not null, primary key # user_id :integer # content :text default("") # created_at :datetime end -
Jimmie Tyrrell revised this gist
May 30, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ }, { "user": { "name": "Han" }, "content": "Second comment" }, -
Jimmie Tyrrell revised this gist
May 30, 2017 . 2 changed files with 44 additions and 44 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,49 +2,6 @@ class NewsfeedController < ApplicationController # Endpoint that returns a JSON object of Posts, each Post with an array of Comments # associated with it. Each Post and Comment also has information about the User # who wrote the content. # TODO: Newsfeed endpoint here end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ [ { "content": "First post", "user": { "name": "Luke" }, "comments": [ { "user": { "name": "Leia" }, "content": "First comment" }, { "user": { "name": "Leia" }, "content": "Second comment" }, ] }, { "content": "Second post", "user": { "name": "Darth Vader" }, "comments": [ { "user": { "name": "Boba Fett" }, "content": "Third comment" }, { "user": { "name": "Jabba" }, "content": "Fourth comment" }, ] } ] -
Jimmie Tyrrell revised this gist
May 30, 2017 . 4 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes. -
Jimmie Tyrrell revised this gist
May 30, 2017 . 4 changed files with 23 additions and 26 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ class Comment < ApplicationRecord belongs_to :user belongs_to :post # id :integer not null, primary key # user_id :integer # post_id :integer # content :text default("") # created_at :datetime end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,29 +1,3 @@ class NewsfeedController < ApplicationController # Endpoint that returns a JSON object of Posts, each Post with an array of Comments # associated with it. Each Post and Comment also has information about the User This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ class Post < ApplicationRecord belongs_to :user # id :integer not null, primary key # user_id :integer # title :string(50) default("") # content :text default("") # created_at :datetime end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ class User < ApplicationRecord # id :integer not null, primary key # name :string(50) default("") end -
Jimmie Tyrrell renamed this gist
May 30, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,7 @@ class Post < ApplicationRecord # user_id :integer # title :string(50) default("") # content :text default("") # created_at :datetime end class Comment < ApplicationRecord @@ -20,6 +21,7 @@ class Comment < ApplicationRecord # user_id :integer # post_id :integer # content :text default("") # created_at :datetime end class NewsfeedController < ApplicationController -
Jimmie Tyrrell revised this gist
May 30, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ class User < ApplicationRecord # id :integer not null, primary key # name :string(50) default("") end class Post < ApplicationRecord -
Jimmie Tyrrell created this gist
May 30, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ class User < ApplicationRecord # id :integer not null, primary key # name :string(50) default("") end class Post < ApplicationRecord belongs_to :user # id :integer not null, primary key # user_id :integer # title :string(50) default("") # content :text default("") end class Comment < ApplicationRecord belongs_to :user belongs_to :post # id :integer not null, primary key # user_id :integer # post_id :integer # content :text default("") end class NewsfeedController < ApplicationController # Endpoint that returns a JSON object of Posts, each Post with an array of Comments # associated with it. Each Post and Comment also has information about the User # who wrote the content. # # [ # { # "content": "First post", # "user": { # "name": "Luke" # }, # "comments": [ # { # "user": { # "name": "Leia" # }, # "content": "First comment" # }, # { # "user": { # "name": "Leia" # }, # "content": "Second comment" # }, # ] # }, # { # "content": "Second post", # "user": { # "name": "Darth Vader" # }, # "comments": [ # { # "user": { # "name": "Boba Fett" # }, # "content": "Third comment" # }, # { # "user": { # "name": "Jabba" # }, # "content": "Fourth comment" # }, # ] # } # ] # TODO: Newsfeed endpoint here end