Adapt backend to enable flagging/unflagging investments

This commit is contained in:
Angel Perez
2018-06-17 23:05:18 -04:00
parent 8ef3e81e03
commit 7bb1da1804
3 changed files with 21 additions and 4 deletions

View File

@@ -3,18 +3,32 @@ module FlagActions
def flag
Flag.flag(current_user, flaggable)
respond_with flaggable, template: "#{controller_name}/_refresh_flag_actions"
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
end
def unflag
Flag.unflag(current_user, flaggable)
respond_with flaggable, template: "#{controller_name}/_refresh_flag_actions"
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
end
private
def flaggable
instance_variable_get("@#{resource_model.to_s.downcase}")
if resource_model.to_s == 'Budget::Investment'
instance_variable_get("@investment")
else
instance_variable_get("@#{resource_model.to_s.downcase}")
end
end
end
end