Skip to content

Commit

Permalink
invert negation in if/else - relationships_controller (#11505)
Browse files Browse the repository at this point in the history
* invert negation in if/else
  • Loading branch information
Dhei-vid authored Oct 21, 2022
1 parent 91f5036 commit a5aecc3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions app/controllers/relationships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ class RelationshipsController < ApplicationController
def create
user = User.find(params[:followed_id])
respond_to do |format|
if !current_user.following?(user)
current_user.follow(user)
format.html { redirect_to URI.parse(request.referer || "/").path, notice: "You have started following " + user.username }
format.js { render "create", locals: { following: true, profile_user: user } }
else
if current_user.following?(user)
format.html {
flash[:error] = "Error in following user"
redirect_to URI.parse(request.referer || "/").path
}
format.js { render "create", locals: { following: false, profile_user: user } }
else
current_user.follow(user)
format.html { redirect_to URI.parse(request.referer || "/").path, notice: "You have started following #{user.username}" }
format.js { render "create", locals: { following: true, profile_user: user } }
end
end
end
Expand All @@ -22,16 +22,16 @@ def destroy
user = User.find_by_id(params[:id])
relation = Relationship.where(follower_id: current_user.id, followed_id: params[:id])
respond_to do |format|
if !relation.nil?
current_user.unfollow(user)
format.html { redirect_to URI.parse(request.referer || "/").path, notice: "You have unfollowed " + user.username }
format.js { render "destroy", locals: { unfollowing: true, profile_user: user } }
else
if relation.nil?
format.html {
flash[:error] = "Error in unfollowing user"
redirect_to URI.parse(request.referer || "/").path
}
format.js { render "destroy", locals: { unfollowing: false, profile_user: user } }
else
current_user.unfollow(user)
format.html { redirect_to URI.parse(request.referer || "/").path, notice: "You have unfollowing #{user.username}" }
format.js { render "destroy", locals: { unfollowing: true, profile_user: user } }
end
end
end
Expand Down

0 comments on commit a5aecc3

Please sign in to comment.