Class: Decidim::Debates::CloseDebateForm

Inherits:
Form show all
Defined in:
decidim-debates/app/forms/decidim/debates/close_debate_form.rb

Overview

This class holds a Form to close debates from Decidim’s public views.

Constant Summary

Constants included from AttributeObject::TypeMap

AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal

Instance Attribute Summary

Attributes inherited from AttributeObject::Form

#context

Instance Method Summary collapse

Methods inherited from AttributeObject::Form

ensure_hash, from_model, from_params, hash_from, infer_model_name, mimic, mimicked_model_name, model_name, #persisted?, #to_key, #to_model, #to_param, #valid?, #with_context

Methods included from AttributeObject::Model

#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h

Instance Method Details

#closed_atObject



15
16
17
# File 'decidim-debates/app/forms/decidim/debates/close_debate_form.rb', line 15

def closed_at
  debate&.closed_at || Time.current
end

#debateObject



28
29
30
# File 'decidim-debates/app/forms/decidim/debates/close_debate_form.rb', line 28

def debate
  @debate ||= Debate.find_by(id:)
end

#map_model(debate) ⇒ Object



19
20
21
22
23
24
25
26
# File 'decidim-debates/app/forms/decidim/debates/close_debate_form.rb', line 19

def map_model(debate)
  super

  # Debates can be translated in different languages from the admin but
  # the public form does not allow it. When a user closes a debate the
  # user locale is taken as the text locale.
  self.conclusions = debate.conclusions&.values&.first
end