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
- #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
40 41 42 |
# File '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 '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 |
#scope ⇒ Object
Finds the Scope from the given scope_id, uses component scope if missing.
Returns a Decidim::Scope
47 48 49 |
# File '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_id ⇒ Object
Scope identifier
Returns the scope identifier related to the debate
54 55 56 |
# File 'app/forms/decidim/debates/debate_form.rb', line 54 def scope_id @scope_id || scope&.id end |