From 6c113d43f9bc1d638664af3ea0885b03db625e03 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Mon, 18 May 2020 14:49:21 +0800 Subject: [PATCH] change follow and unfollow render json --- app/controllers/watchers_controller.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index ab5499a1f..566941e5f 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -12,7 +12,12 @@ class WatchersController < ApplicationController begin return normal_status(2, "你还没有关注哦") unless current_user.watched?(@target) current_user.unwatch!(@target) - render_ok({watchers_count: @target.watchers_count, watched: false}) + if @target_type.downcase == "project" + render_ok({watchers_count: @target.watchers_count, watched: false}) + else + render_ok({ watched: false}) + end + rescue Exception => e uid_logger_error(e.message) tip_exception(e.message) @@ -24,7 +29,11 @@ class WatchersController < ApplicationController begin return normal_status(2, "你已关注了") if current_user.watched?(@target) current_user.watch!(@target) - render_ok({watchers_count: @target.watchers_count, watched: true}) + if @target_type.downcase == "project" + render_ok({watchers_count: @target.watchers_count, watched: true}) + else + render_ok({ watched: false}) + end rescue Exception => e uid_logger_error(e.message) tip_exception(e.message) @@ -43,12 +52,12 @@ class WatchersController < ApplicationController private def get_target - target_type = params[:target_type].to_s - case target_type + @target_type = params[:target_type].to_s + case @target_type when "project" - @target = target_type.capitalize.constantize.find_by(id: params[:id]) + @target = @target_type.capitalize.constantize.find_by(id: params[:id]) else - @target = target_type.capitalize.constantize.find_by(login: params[:id]) #用户 + @target = @target_type.capitalize.constantize.find_by(login: params[:id]) #用户 end unless @target.present?