Files
grecia/app/controllers/concerns/flag_actions.rb
Javi Martín efc46fe6c8 Add Performance/StringIdentifierArgument rule
It was added in rubocop-performance 1.13.0. We were already applying it
in most places.

We aren't adding it for performance reasons but in order to make the
code more consistent.
2023-01-11 16:05:20 +01:00

28 lines
650 B
Ruby

module FlagActions
extend ActiveSupport::Concern
def flag
Flag.flag(current_user, flaggable)
render "shared/_refresh_flag_actions", locals: { flaggable: flaggable }
end
def unflag
Flag.unflag(current_user, flaggable)
render "shared/_refresh_flag_actions", locals: { flaggable: flaggable }
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