From b44e6594c5fb1ad1513ef00ceee7ca381816bf76 Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Thu, 2 Nov 2023 13:12:11 -0300 Subject: [PATCH 01/14] dinamic user list creation --- app/controllers/users_controller.rb | 9 +++-- app/views/users/index.html.erb | 55 +++++------------------------ 2 files changed, 16 insertions(+), 48 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4e99c3c..0048614 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,10 @@ class UsersController < ApplicationController - def index; end + def index + @users = User.all + end - def show; end + def show + @user = User.find(params[:id]) + @posts = @user.posts + end end diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 9219bd9..e1c9922 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,50 +1,13 @@ From e671d92c2f2bef226c31ab82a4f46edc01b2174a Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Thu, 2 Nov 2023 13:17:25 -0300 Subject: [PATCH 02/14] divide code into partial --- app/views/users/_user_card.html.erb | 9 +++++++++ app/views/users/index.html.erb | 14 +++----------- 2 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 app/views/users/_user_card.html.erb diff --git a/app/views/users/_user_card.html.erb b/app/views/users/_user_card.html.erb new file mode 100644 index 0000000..5515e80 --- /dev/null +++ b/app/views/users/_user_card.html.erb @@ -0,0 +1,9 @@ +
  • + + user-image +
    +

    <%= user.name %>

    +

    Number of posts: <%= user.post_counter || 0 %>

    +
    +
    +
  • diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index e1c9922..3a97f39 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,13 +1,5 @@ From 677466414a05538d67e716ff81ddd363faeb56d6 Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Thu, 2 Nov 2023 17:59:53 -0300 Subject: [PATCH 03/14] reduce code --- app/assets/stylesheets/application.css | 6 ++++++ app/views/users/_user_card.html.erb | 10 ++++------ app/views/users/index.html.erb | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 764e7a9..da55d47 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -4,6 +4,11 @@ font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; } +.users-title{ + text-align: center; + margin: 50px auto; +} + .user-card { align-self: center; justify-content: space-between; @@ -27,6 +32,7 @@ padding: 20px; display: flex; justify-content: space-between; + text-decoration: none; } .card-name { diff --git a/app/views/users/_user_card.html.erb b/app/views/users/_user_card.html.erb index 5515e80..bed89a3 100644 --- a/app/views/users/_user_card.html.erb +++ b/app/views/users/_user_card.html.erb @@ -1,9 +1,7 @@
  • - user-image -
    -

    <%= user.name %>

    -

    Number of posts: <%= user.post_counter || 0 %>

    -
    -
    + +

    <%= user.name %>

    +

    Number of posts: <%= user.post_counter || 0 %>

    +
  • diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 3a97f39..32e0911 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,4 +1,5 @@ -
      +

      Users

      +
        <% @users.each do |user| %> <%= render 'user_card', user: user %> <% end %> From aa482fefa2e4d0fc00e0685ead2b2741176f1d0e Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Thu, 2 Nov 2023 19:04:16 -0300 Subject: [PATCH 04/14] convert show.html.erb into partials --- app/assets/stylesheets/application.css | 12 +++------ app/views/users/_user_card.html.erb | 4 +-- app/views/users/_user_post.html.erb | 6 +++++ app/views/users/index.html.erb | 10 +++---- app/views/users/show.html.erb | 37 ++++++-------------------- 5 files changed, 24 insertions(+), 45 deletions(-) create mode 100644 app/views/users/_user_post.html.erb diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index da55d47..e15bfb3 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -4,9 +4,9 @@ font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; } -.users-title{ +.title{ text-align: center; - margin: 50px auto; + text-decoration: underline; } .user-card { @@ -60,18 +60,14 @@ border: 2px solid #ccc; max-width: 70%; padding: 20px; + min-width: 70%; } .user-posts-list { display: flex; flex-direction: column; + align-items: center; justify-content: center; - align-content: center; -} - -.user-posts-title { - text-align: center; - text-decoration: underline; } .user-post-date { diff --git a/app/views/users/_user_card.html.erb b/app/views/users/_user_card.html.erb index bed89a3..a4aba88 100644 --- a/app/views/users/_user_card.html.erb +++ b/app/views/users/_user_card.html.erb @@ -1,7 +1,7 @@ -
      • +
      • + diff --git a/app/views/users/_user_post.html.erb b/app/views/users/_user_post.html.erb new file mode 100644 index 0000000..54a1874 --- /dev/null +++ b/app/views/users/_user_post.html.erb @@ -0,0 +1,6 @@ +
        +

        <%= post.title %>

        +
        +

        <%= post.text %>

        + +
        \ No newline at end of file diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 32e0911..59c7b30 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,6 +1,4 @@ -

        Users

        -
          - <% @users.each do |user| %> - <%= render 'user_card', user: user %> - <% end %> -
        +

        Users

        +<% @users.each do |user| %> + <%= render 'user_card', user: user %> +<% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 7fd3504..9fdc36c 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,41 +1,20 @@ -
        - user-image -
        -

        User Name

        -

        Number of posts: 0

        -
        -
        +<%= render 'user_card', user: @user %>

        Bio


        - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + <%= @user.bio %>

        +

        Posts

        -

        Posts

        -
        -

        Post Title

        -
        -

        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

        - -
        + <% @posts.each do |post| %> + <%= render 'user_post', post: post %> + <% end %> + +
        -
        -

        Post Title

        -
        -

        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

        - -
        -
        -

        Post Title

        -
        -

        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

        - -
        - - From 58fa7866e3d104b843fd33a08f54a711fd3ed349 Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Thu, 2 Nov 2023 19:06:17 -0300 Subject: [PATCH 05/14] turn user_bio into partial --- app/views/users/_user_bio.html.erb | 7 +++++++ app/views/users/show.html.erb | 8 +------- 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 app/views/users/_user_bio.html.erb diff --git a/app/views/users/_user_bio.html.erb b/app/views/users/_user_bio.html.erb new file mode 100644 index 0000000..50964b7 --- /dev/null +++ b/app/views/users/_user_bio.html.erb @@ -0,0 +1,7 @@ +
        +

        Bio

        +
        +

        + <%= user.bio %> +

        +
        \ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 9fdc36c..491788f 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,12 +1,6 @@ <%= render 'user_card', user: @user %> -
        -

        Bio

        -
        -

        - <%= @user.bio %> -

        -
        +<%= render 'user_bio', user: @user %>

        Posts

        From 3369bf4872c9d9eb22e8fe6f693b57ba48677be9 Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Thu, 2 Nov 2023 19:26:51 -0300 Subject: [PATCH 06/14] minimize app css --- app/assets/stylesheets/application.css | 22 +++++----------------- app/views/users/_user_bio.html.erb | 2 +- app/views/users/_user_card.html.erb | 2 +- app/views/users/_user_post.html.erb | 4 ++-- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index e15bfb3..74e3df3 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -39,28 +39,21 @@ align-self: center; } -.card-counter { +.counter { align-self: end; justify-self: end; } -.user-bio { - align-self: center; - justify-content: center; - margin: 50px auto; - border: 2px solid #ccc; - max-width: 70%; - padding: 20px; -} - -.user-post { +.info-card { + display: flex; + flex-direction: column; align-self: center; justify-content: center; margin: 50px auto; border: 2px solid #ccc; max-width: 70%; - padding: 20px; min-width: 70%; + padding: 20px; } .user-posts-list { @@ -70,11 +63,6 @@ justify-content: center; } -.user-post-date { - text-align: right; - font-size: small; -} - .user-posts-button { align-self: center; margin: 10px 0; diff --git a/app/views/users/_user_bio.html.erb b/app/views/users/_user_bio.html.erb index 50964b7..8557c20 100644 --- a/app/views/users/_user_bio.html.erb +++ b/app/views/users/_user_bio.html.erb @@ -1,4 +1,4 @@ -
        +

        Bio


        diff --git a/app/views/users/_user_card.html.erb b/app/views/users/_user_card.html.erb index a4aba88..132d607 100644 --- a/app/views/users/_user_card.html.erb +++ b/app/views/users/_user_card.html.erb @@ -2,6 +2,6 @@ user-image

        <%= user.name %>

        -

        Number of posts: <%= user.post_counter || 0 %>

        +

        Number of posts: <%= user.post_counter || 0 %>

        diff --git a/app/views/users/_user_post.html.erb b/app/views/users/_user_post.html.erb index 54a1874..2ddc3f2 100644 --- a/app/views/users/_user_post.html.erb +++ b/app/views/users/_user_post.html.erb @@ -1,6 +1,6 @@ -
        +

        <%= post.title %>


        <%= post.text %>

        - +

        Comments: <%= post.comments_counter || 0 %>, Likes: <%= post.likes_counter || 0 %>

        \ No newline at end of file From 9311be1940316dc9f611358c070d420c6da613d5 Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Thu, 2 Nov 2023 21:30:19 -0300 Subject: [PATCH 07/14] add link-to posts button --- app/assets/stylesheets/application.css | 7 ++++++- app/controllers/posts_controller.rb | 8 ++++++-- app/views/posts/index.html.erb | 5 +++++ app/views/users/show.html.erb | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 74e3df3..6dd6642 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -64,6 +64,9 @@ } .user-posts-button { + display: flex; /* Use flexbox */ + align-items: center; /* Center vertically */ + justify-content: center; /* Center horizontally */ align-self: center; margin: 10px 0; padding: 10px; @@ -72,5 +75,7 @@ background-color: #fff; cursor: pointer; width: 10%; - height: 50px; + height: 30px; + text-align: center; + text-decoration: none; } diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 4504b67..bdf8c48 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,5 +1,9 @@ class PostsController < ApplicationController - def index; end + def index + @userPosts = User.find(params[:user_id]).posts + end - def show; end + def show + + end end diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index c7991f1..bacef31 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -1 +1,6 @@

        Hello posts

        +<% @userPosts.each do |post| %> + <%= render 'post_card', post: post %> +<% end %> +``` +### \ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 491788f..5d320b9 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -7,7 +7,7 @@ <% @posts.each do |post| %> <%= render 'user_post', post: post %> <% end %> - + <%= link_to "See all posts", user_posts_path(@user), class: "user-posts-button" %>
        From 462b78fd71901b33621b2d00eb992c633596a3ef Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Thu, 2 Nov 2023 21:42:24 -0300 Subject: [PATCH 08/14] create posts index template --- app/assets/stylesheets/application.css | 2 +- app/controllers/posts_controller.rb | 3 ++- app/views/{users => partials}/_user_bio.html.erb | 0 app/views/{users => partials}/_user_card.html.erb | 0 app/views/{users => partials}/_user_post.html.erb | 0 app/views/posts/index.html.erb | 6 ++---- app/views/users/index.html.erb | 2 +- app/views/users/show.html.erb | 6 +++--- 8 files changed, 9 insertions(+), 10 deletions(-) rename app/views/{users => partials}/_user_bio.html.erb (100%) rename app/views/{users => partials}/_user_card.html.erb (100%) rename app/views/{users => partials}/_user_post.html.erb (100%) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 6dd6642..89a4c4a 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -49,7 +49,7 @@ flex-direction: column; align-self: center; justify-content: center; - margin: 50px auto; + margin: 20px auto; border: 2px solid #ccc; max-width: 70%; min-width: 70%; diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index bdf8c48..092e764 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,6 +1,7 @@ class PostsController < ApplicationController def index - @userPosts = User.find(params[:user_id]).posts + @user = User.find(params[:user_id]) + @userPosts = @user.posts end def show diff --git a/app/views/users/_user_bio.html.erb b/app/views/partials/_user_bio.html.erb similarity index 100% rename from app/views/users/_user_bio.html.erb rename to app/views/partials/_user_bio.html.erb diff --git a/app/views/users/_user_card.html.erb b/app/views/partials/_user_card.html.erb similarity index 100% rename from app/views/users/_user_card.html.erb rename to app/views/partials/_user_card.html.erb diff --git a/app/views/users/_user_post.html.erb b/app/views/partials/_user_post.html.erb similarity index 100% rename from app/views/users/_user_post.html.erb rename to app/views/partials/_user_post.html.erb diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index bacef31..b255a77 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -1,6 +1,4 @@ -

        Hello posts

        +<%= render 'partials/user_card', user: @user %> <% @userPosts.each do |post| %> - <%= render 'post_card', post: post %> + <%= render 'partials/user_post', post: post %> <% end %> -``` -### \ No newline at end of file diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 59c7b30..911cfe4 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,4 +1,4 @@

        Users

        <% @users.each do |user| %> - <%= render 'user_card', user: user %> + <%= render 'partials/user_card', user: user %> <% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 5d320b9..b9b4c84 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,11 +1,11 @@ -<%= render 'user_card', user: @user %> +<%= render 'partials/user_card', user: @user %> -<%= render 'user_bio', user: @user %> +<%= render 'partials/user_bio', user: @user %>

        Posts

        <% @posts.each do |post| %> - <%= render 'user_post', post: post %> + <%= render 'partials/user_post', post: post %> <% end %> <%= link_to "See all posts", user_posts_path(@user), class: "user-posts-button" %>
        From 0971ed72544966a6196f11ca71f3bc22ce7cdb06 Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Fri, 3 Nov 2023 11:47:28 -0300 Subject: [PATCH 09/14] create post index template --- app/controllers/posts_controller.rb | 2 +- app/views/partials/_post_comments.html.erb | 0 app/views/posts/index.html.erb | 4 ++++ app/views/users/show.html.erb | 6 +++--- 4 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 app/views/partials/_post_comments.html.erb diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 092e764..d5ac86e 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,7 +1,7 @@ class PostsController < ApplicationController def index @user = User.find(params[:user_id]) - @userPosts = @user.posts + @userPosts = @user.recent_posts end def show diff --git a/app/views/partials/_post_comments.html.erb b/app/views/partials/_post_comments.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index b255a77..97cd823 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -1,4 +1,8 @@ <%= render 'partials/user_card', user: @user %> + <% @userPosts.each do |post| %> <%= render 'partials/user_post', post: post %> + <% post.recent_comments.each do |comment| %> +

        <%= comment.text %>

        + <% end %> <% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index b9b4c84..8028ec1 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -4,11 +4,11 @@

        Posts

        +<% if @posts.empty? %> +

        No posts yet

        +<% end %> <% @posts.each do |post| %> <%= render 'partials/user_post', post: post %> <% end %> <%= link_to "See all posts", user_posts_path(@user), class: "user-posts-button" %>
        - - - From 5146eb6da41ad7f50221de60cc0cb979e075d2b1 Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Fri, 3 Nov 2023 14:20:42 -0300 Subject: [PATCH 10/14] add post_comments and link to post/:id --- app/assets/stylesheets/application.css | 10 +++++++++- app/views/partials/_post_comments.html.erb | 5 +++++ app/views/partials/_user_card.html.erb | 2 +- app/views/partials/_user_post.html.erb | 4 ++-- app/views/posts/index.html.erb | 6 ++---- app/views/users/show.html.erb | 2 +- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 89a4c4a..881965c 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -49,7 +49,7 @@ flex-direction: column; align-self: center; justify-content: center; - margin: 20px auto; + margin: 40px auto 0 auto; border: 2px solid #ccc; max-width: 70%; min-width: 70%; @@ -79,3 +79,11 @@ text-align: center; text-decoration: none; } + +.comments-card{ + margin-top: 0; +} + +.comments-card :nth-child(odd){ + background-color: #ccc; +} diff --git a/app/views/partials/_post_comments.html.erb b/app/views/partials/_post_comments.html.erb index e69de29..f7b6bdd 100644 --- a/app/views/partials/_post_comments.html.erb +++ b/app/views/partials/_post_comments.html.erb @@ -0,0 +1,5 @@ +
        +<% post.recent_comments.reverse.each do |comment| %> +

        <%= comment.text %>

        +<% end %> +
        \ No newline at end of file diff --git a/app/views/partials/_user_card.html.erb b/app/views/partials/_user_card.html.erb index 132d607..5026e03 100644 --- a/app/views/partials/_user_card.html.erb +++ b/app/views/partials/_user_card.html.erb @@ -1,5 +1,5 @@
        - user-image +<%= image_tag user.photo, class: "user-image" if user.photo.present? %>

        <%= user.name %>

        Number of posts: <%= user.post_counter || 0 %>

        diff --git a/app/views/partials/_user_post.html.erb b/app/views/partials/_user_post.html.erb index 2ddc3f2..d6be891 100644 --- a/app/views/partials/_user_post.html.erb +++ b/app/views/partials/_user_post.html.erb @@ -1,6 +1,6 @@ -
        \ No newline at end of file + \ No newline at end of file diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 97cd823..bf37f0b 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -1,8 +1,6 @@ <%= render 'partials/user_card', user: @user %> <% @userPosts.each do |post| %> - <%= render 'partials/user_post', post: post %> - <% post.recent_comments.each do |comment| %> -

        <%= comment.text %>

        - <% end %> + <%= render 'partials/user_post', post: post, user: @user %> + <%= render 'partials/post_comments', post: post %> <% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 8028ec1..cbe8bc4 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -8,7 +8,7 @@

        No posts yet

        <% end %> <% @posts.each do |post| %> - <%= render 'partials/user_post', post: post %> + <%= render 'partials/user_post', post: post, user: @user %> <% end %> <%= link_to "See all posts", user_posts_path(@user), class: "user-posts-button" %>
        From 9e52f72d1bf087a38ec28088fa1f0ab91981d8b3 Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Fri, 3 Nov 2023 14:54:34 -0300 Subject: [PATCH 11/14] add empty posts message, post/:post_id template, back to main page link --- app/controllers/posts_controller.rb | 4 +++- app/views/posts/index.html.erb | 6 ++++++ app/views/posts/show.html.erb | 4 +++- app/views/users/show.html.erb | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index d5ac86e..8dec7ff 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -5,6 +5,8 @@ def index end def show - + @user = User.find(params[:user_id]) + @post = @user.posts.find(params[:id]) + @comments = @post.comments.all end end diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index bf37f0b..3ca2446 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -1,6 +1,12 @@ +<%= link_to "back to main page", root_path %> <%= render 'partials/user_card', user: @user %> +
        +<% if @userPosts.empty? %> +

        No posts yet

        +<% end %> <% @userPosts.each do |post| %> <%= render 'partials/user_post', post: post, user: @user %> <%= render 'partials/post_comments', post: post %> <% end %> +
        \ No newline at end of file diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index b43524a..98ff14e 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -1 +1,3 @@ -

        Goodbye posts

        +<%= link_to "back to main page", root_path %> +<%= render 'partials/user_post', post: @post, user: @user %> +<%= render 'partials/post_comments', post: @post %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index cbe8bc4..33ba4e4 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,3 +1,4 @@ +<%= link_to "back to main page", root_path %> <%= render 'partials/user_card', user: @user %> <%= render 'partials/user_bio', user: @user %> From 57cbeeead19267d574e70f1f66a56aac28f7bf70 Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Fri, 3 Nov 2023 17:05:00 -0300 Subject: [PATCH 12/14] fix linters --- app/assets/stylesheets/application.css | 16 +++++++++------- app/controllers/posts_controller.rb | 8 ++++---- app/controllers/users_controller.rb | 6 +++--- app/views/partials/_post_comments.html.erb | 2 +- app/views/posts/index.html.erb | 4 ++-- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 881965c..d75da0d 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -4,7 +4,7 @@ font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; } -.title{ +.title { text-align: center; text-decoration: underline; } @@ -54,6 +54,8 @@ max-width: 70%; min-width: 70%; padding: 20px; + text-decoration: none; + color: black; } .user-posts-list { @@ -64,9 +66,9 @@ } .user-posts-button { - display: flex; /* Use flexbox */ - align-items: center; /* Center vertically */ - justify-content: center; /* Center horizontally */ + display: flex; + align-items: center; + justify-content: center; align-self: center; margin: 10px 0; padding: 10px; @@ -80,10 +82,10 @@ text-decoration: none; } -.comments-card{ - margin-top: 0; +.comments-card { + margin-top: 0; } -.comments-card :nth-child(odd){ +.comments-card :nth-child(odd) { background-color: #ccc; } diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 8dec7ff..1a98360 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,12 +1,12 @@ class PostsController < ApplicationController def index @user = User.find(params[:user_id]) - @userPosts = @user.recent_posts + @use_posts = @user.recent_posts end def show - @user = User.find(params[:user_id]) - @post = @user.posts.find(params[:id]) - @comments = @post.comments.all + @user = User.find(params[:user_id]) + @post = @user.posts.find(params[:id]) + @comments = @post.comments.all end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0048614..f9c879e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,10 +1,10 @@ class UsersController < ApplicationController def index - @users = User.all + @users = User.all end def show - @user = User.find(params[:id]) - @posts = @user.posts + @user = User.find(params[:id]) + @posts = @user.posts end end diff --git a/app/views/partials/_post_comments.html.erb b/app/views/partials/_post_comments.html.erb index f7b6bdd..aa2e919 100644 --- a/app/views/partials/_post_comments.html.erb +++ b/app/views/partials/_post_comments.html.erb @@ -1,5 +1,5 @@
        <% post.recent_comments.reverse.each do |comment| %> -

        <%= comment.text %>

        +

        <%= comment.user.name %>: <%= comment.text %>

        <% end %>
        \ No newline at end of file diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 3ca2446..e727951 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -2,10 +2,10 @@ <%= render 'partials/user_card', user: @user %>
        -<% if @userPosts.empty? %> +<% if @user_posts.empty? %>

        No posts yet

        <% end %> -<% @userPosts.each do |post| %> +<% @user_posts.each do |post| %> <%= render 'partials/user_post', post: post, user: @user %> <%= render 'partials/post_comments', post: post %> <% end %> From 0300462ff76ed90637e0d4c4dd26a5de72d70ef4 Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Fri, 3 Nov 2023 18:00:52 -0300 Subject: [PATCH 13/14] fix typo --- app/controllers/posts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 1a98360..443c789 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,7 +1,7 @@ class PostsController < ApplicationController def index @user = User.find(params[:user_id]) - @use_posts = @user.recent_posts + @user_posts = @user.recent_posts end def show From 8c42c2206e9da9ddb722b4661235c27a410bab98 Mon Sep 17 00:00:00 2001 From: Tomas Esquivel Date: Fri, 3 Nov 2023 18:27:36 -0300 Subject: [PATCH 14/14] fix recent_posts --- app/controllers/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f9c879e..ef3de85 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,6 +5,6 @@ def index def show @user = User.find(params[:id]) - @posts = @user.posts + @posts = @user.recent_posts end end