Class: Decidim::Debates::DebateForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Debates::DebateForm
- Includes:
- TranslatableAttributes
- Defined in:
- 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
- #category ⇒ Object
- #debate ⇒ Object
- #map_model(debate) ⇒ Object
-
#scope ⇒ Object
Finds the Scope from the given scope_id, uses component scope if missing.
-
#scope_id ⇒ Object
Scope identifier.
Instance Method Details
#category ⇒ Object
37 38 39 |
# File 'app/forms/decidim/debates/debate_form.rb', line 37 def category @category ||= current_component.categories.find_by(id: category_id) end |
#debate ⇒ Object
55 56 57 |
# File 'app/forms/decidim/debates/debate_form.rb', line 55 def debate @debate ||= Debate.find_by(id:) end |
#map_model(debate) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/forms/decidim/debates/debate_form.rb', line 22 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 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 |
#scope ⇒ Object
Finds the Scope from the given scope_id, uses component scope if missing.
Returns a Decidim::Scope
44 45 46 |
# File 'app/forms/decidim/debates/debate_form.rb', line 44 def scope @scope ||= @attributes["scope_id"].value ? current_component.scopes.find_by(id: @attributes["scope_id"].value) : current_component.scope end |
#scope_id ⇒ Object
Scope identifier
Returns the scope identifier related to the debate
51 52 53 |
# File 'app/forms/decidim/debates/debate_form.rb', line 51 def scope_id super || scope&.id end |