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.
This commit is contained in:
@@ -35,13 +35,15 @@ class CommentsController < ApplicationController
|
|||||||
def flag
|
def flag
|
||||||
Flag.flag(current_user, @comment)
|
Flag.flag(current_user, @comment)
|
||||||
set_comment_flags(@comment)
|
set_comment_flags(@comment)
|
||||||
respond_with @comment, template: "comments/_refresh_flag_actions"
|
|
||||||
|
render "comments/_refresh_flag_actions"
|
||||||
end
|
end
|
||||||
|
|
||||||
def unflag
|
def unflag
|
||||||
Flag.unflag(current_user, @comment)
|
Flag.unflag(current_user, @comment)
|
||||||
set_comment_flags(@comment)
|
set_comment_flags(@comment)
|
||||||
respond_with @comment, template: "comments/_refresh_flag_actions"
|
|
||||||
|
render "comments/_refresh_flag_actions"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -4,21 +4,13 @@ module FlagActions
|
|||||||
def flag
|
def flag
|
||||||
Flag.flag(current_user, flaggable)
|
Flag.flag(current_user, flaggable)
|
||||||
|
|
||||||
if controller_name == "investments"
|
render "_refresh_flag_actions"
|
||||||
respond_with flaggable, template: "budgets/#{controller_name}/_refresh_flag_actions"
|
|
||||||
else
|
|
||||||
respond_with flaggable, template: "#{controller_name}/_refresh_flag_actions"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def unflag
|
def unflag
|
||||||
Flag.unflag(current_user, flaggable)
|
Flag.unflag(current_user, flaggable)
|
||||||
|
|
||||||
if controller_name == "investments"
|
render "_refresh_flag_actions"
|
||||||
respond_with flaggable, template: "budgets/#{controller_name}/_refresh_flag_actions"
|
|
||||||
else
|
|
||||||
respond_with flaggable, template: "#{controller_name}/_refresh_flag_actions"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
Reference in New Issue
Block a user