From 0d7c2c7a7ceebaaa2248924af323297cf6ed676f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 20 Mar 2020 16:11:29 +0100 Subject: [PATCH] Simplify rendering flag actions The `respond_with` method is no longer part of Rails (it's now part of the responders gem) and we barely use it. Using a template forced us to use different criteria for different controllers. This change will also make it easier to fix the flag/unflag actions for legislation proposals. With the old code, we would have to add another condition for the legislation/proposals controller. --- app/controllers/comments_controller.rb | 6 ++++-- app/controllers/concerns/flag_actions.rb | 12 ++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 0cb2a5b44..49dee85e9 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -35,13 +35,15 @@ class CommentsController < ApplicationController def flag Flag.flag(current_user, @comment) set_comment_flags(@comment) - respond_with @comment, template: "comments/_refresh_flag_actions" + + render "comments/_refresh_flag_actions" end def unflag Flag.unflag(current_user, @comment) set_comment_flags(@comment) - respond_with @comment, template: "comments/_refresh_flag_actions" + + render "comments/_refresh_flag_actions" end private diff --git a/app/controllers/concerns/flag_actions.rb b/app/controllers/concerns/flag_actions.rb index 5984c24e0..cc305dca1 100644 --- a/app/controllers/concerns/flag_actions.rb +++ b/app/controllers/concerns/flag_actions.rb @@ -4,21 +4,13 @@ module FlagActions def flag Flag.flag(current_user, flaggable) - if controller_name == "investments" - respond_with flaggable, template: "budgets/#{controller_name}/_refresh_flag_actions" - else - respond_with flaggable, template: "#{controller_name}/_refresh_flag_actions" - end + render "_refresh_flag_actions" end def unflag Flag.unflag(current_user, flaggable) - if controller_name == "investments" - respond_with flaggable, template: "budgets/#{controller_name}/_refresh_flag_actions" - else - respond_with flaggable, template: "#{controller_name}/_refresh_flag_actions" - end + render "_refresh_flag_actions" end private