Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invert negation in if/else - relationships_controller #11505

Merged
merged 9 commits into from
Oct 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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