app/forms/decidim/debates/debate_form.rb in decidim-debates-0.26.10 vs app/forms/decidim/debates/debate_form.rb in decidim-debates-0.27.0.rc1

- old
+ new

@@ -9,23 +9,20 @@ attribute :title, String attribute :description, String attribute :category_id, Integer attribute :scope_id, Integer attribute :user_group_id, Integer - attribute :debate, Debate validates :title, presence: true validates :description, presence: true validates :category, presence: true, if: ->(form) { form.category_id.present? } validate :editable_by_user validates :scope_id, scope_belongs_to_component: true, if: ->(form) { form.scope_id.present? } 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 @@ -43,17 +40,21 @@ # Finds the Scope from the given scope_id, uses component scope if missing. # # Returns a Decidim::Scope def scope - @scope ||= @scope_id ? current_component.scopes.find_by(id: @scope_id) : current_component.scope + @scope ||= @attributes["scope_id"].value ? current_component.scopes.find_by(id: @attributes["scope_id"].value) : current_component.scope end # Scope identifier # # Returns the scope identifier related to the debate def scope_id - @scope_id || scope&.id + super || scope&.id + end + + def debate + @debate ||= Debate.find_by(id: id) end private def editable_by_user