Files
nairobi/app/controllers/concerns/flag_actions.rb
volcov 09fd3ab44a Fix legislation proposals flag actions
We were treating legislation proposals as if they were proposals,
omitting the "legislation" namespace, and so we were flagging/unflagging
proposals when we wanted to flag/unflag a legislation proposal.
2020-07-07 23:39:21 +02:00

28 lines
570 B
Ruby

module FlagActions
extend ActiveSupport::Concern
def flag
Flag.flag(current_user, flaggable)
render "_refresh_flag_actions"
end
def unflag
Flag.unflag(current_user, flaggable)
render "_refresh_flag_actions"
end
private
def flaggable
if resource_model.to_s == "Budget::Investment"
instance_variable_get("@investment")
elsif resource_model.to_s == "Legislation::Proposal"
instance_variable_get("@proposal")
else
instance_variable_get("@#{resource_model.to_s.downcase}")
end
end
end