From e4c1739fd988d850e4113019e242e1478e05a211 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 10 Mar 2021 16:09:15 +0500 Subject: [PATCH] Display followers and following --- app/controllers/profiles/followers_controller.rb | 9 +++++++++ app/controllers/profiles/following_controller.rb | 9 +++++++++ app/views/profiles/followers/index.html.erb | 11 +++++++++++ app/views/profiles/following/index.html.erb | 11 +++++++++++ app/views/profiles/show.html.erb | 8 ++++---- config/routes.rb | 5 ++++- 6 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 app/controllers/profiles/followers_controller.rb create mode 100644 app/controllers/profiles/following_controller.rb create mode 100644 app/views/profiles/followers/index.html.erb create mode 100644 app/views/profiles/following/index.html.erb diff --git a/app/controllers/profiles/followers_controller.rb b/app/controllers/profiles/followers_controller.rb new file mode 100644 index 0000000..428ca97 --- /dev/null +++ b/app/controllers/profiles/followers_controller.rb @@ -0,0 +1,9 @@ +class Profiles::FollowersController < ApplicationController + before_action :set_profile + +private + + def set_profile + @profile = Profile.find params[:profile_id] + end +end diff --git a/app/controllers/profiles/following_controller.rb b/app/controllers/profiles/following_controller.rb new file mode 100644 index 0000000..63e89e7 --- /dev/null +++ b/app/controllers/profiles/following_controller.rb @@ -0,0 +1,9 @@ +class Profiles::FollowingController < ApplicationController + before_action :set_profile + +private + + def set_profile + @profile = Profile.find params[:profile_id] + end +end diff --git a/app/views/profiles/followers/index.html.erb b/app/views/profiles/followers/index.html.erb new file mode 100644 index 0000000..c12ebc7 --- /dev/null +++ b/app/views/profiles/followers/index.html.erb @@ -0,0 +1,11 @@ +
+ ❮ <%= link_to @profile.full_name, @profile %> +
+ +<% if @profile.following_profiles.present? %> + +<% end %> diff --git a/app/views/profiles/following/index.html.erb b/app/views/profiles/following/index.html.erb new file mode 100644 index 0000000..fbf0c14 --- /dev/null +++ b/app/views/profiles/following/index.html.erb @@ -0,0 +1,11 @@ +
+ ❮ <%= link_to @profile.full_name, @profile %> +
+ +<% if @profile.followed_profiles.present? %> + +<% end %> diff --git a/app/views/profiles/show.html.erb b/app/views/profiles/show.html.erb index cedbb3b..360dccd 100644 --- a/app/views/profiles/show.html.erb +++ b/app/views/profiles/show.html.erb @@ -1,11 +1,11 @@

<%= @profile.full_name %>

- <%= @profile.following_profiles.count %> - Followers + <%= link_to "#{@profile.following_profiles.count} Followers", + profile_followers_path(@profile) %> • - <%= @profile.followed_profiles.count %> - Following + <%= link_to "#{@profile.followed_profiles.count} Following", + profile_following_index_path(@profile) %>

<%= @profile.description %>

diff --git a/config/routes.rb b/config/routes.rb index b3810bf..2b95b3d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ Rails.application.routes.draw do root to: 'home#show' - resources :profiles, only: %i[index show] + resources :profiles, only: %i[index show] do + resources :followers, controller: 'profiles/followers', only: :index + resources :following, controller: 'profiles/following', only: :index + end end