Class: Decidim::Debates::DebateForm

Inherits:
Form
  • Object
show all
Includes:
TranslatableAttributes
Defined in:
decidim-debates/app/forms/decidim/debates/debate_form.rb

Overview

This class holds a Form to create/update debates from Decidim's public views.

Instance Method Summary collapse

Methods included from TranslatableAttributes

#default_locale?

Instance Method Details

#categoryObject


40
41
42
# File 'decidim-debates/app/forms/decidim/debates/debate_form.rb', line 40

def category
  @category ||= current_component.categories.find_by(id: category_id)
end

#map_model(debate) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'decidim-debates/app/forms/decidim/debates/debate_form.rb', line 23

def map_model(debate)
  super
  self.debate = debate

  # Debates can be translated in different languages from the admin but
  # the public form doesn't allow it. When a user creates a debate the
  # user locale is taken as the text locale.
  self.title = debate.title.values.first
  self.description = debate.description.values.first
  self.user_group_id = debate.decidim_user_group_id

  if debate.category.present?
    self.category_id = debate.category.id
    @category = debate.category
  end
end

#scopeObject

Finds the Scope from the given scope_id, uses component scope if missing.

Returns a Decidim::Scope


47
48
49
# File 'decidim-debates/app/forms/decidim/debates/debate_form.rb', line 47

def scope
  @scope ||= @scope_id ? current_component.scopes.find_by(id: @scope_id) : current_component.scope
end

#scope_idObject

Scope identifier

Returns the scope identifier related to the debate


54
55
56
# File 'decidim-debates/app/forms/decidim/debates/debate_form.rb', line 54

def scope_id
  @scope_id || scope&.id
end