im trying to add acts a follower to my app so a user can follow other users and on the tweets index page only display the current users tweets and the tweets of the people they are following. i currently have a "follow" button on the user show page, but i would expect it to change into "following" on a click, but nothing changes. ive looked at other questions and documentation, but no luck. thank you.
Users show view:
<% if current_user.following?(@user) %>
<%= button_to "Following", {action: "unfollow", id: @user.id}, method: "post", class: "btn btn-secondary btn_unfollow", remote: true %>
<% else current_user != @user %>
<%= button_to "Follow", {action: "follow", id: @user.id}, method: "post", class: "btn btn-primary btn_follow", remote: true %>
<% end %>
Users Controller:
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@tweets = @user.tweets.order('created_at DESC')
authorize @user
end
def follow
@current_user.follow(@user)
@follow = Follow.find_by(follower: @current_user, followable: @user)
# @user = User.find(params[:id])
# current_user.follow(@user)
# current_user.follow(@user)
# redirect to user_path(@user)
# respond_to :js
end
def unfollow
@user = User.find(params[:id])
@current_user.stop_following(@user)
# current_user.stop_following(@user)
# redirect_to user_path(@user)
# respond_to :js
end
end
Routes:
resources :users do
member do
get :follow
get :unfollow
end
end