Add support for open-ended questions in admin section

Introduce a new "open" votation type for poll questions in the admin
interface. This type allows open answers provided by the user.
This commit is contained in:
taitus
2025-08-06 11:12:08 +02:00
parent eb10a3135b
commit 4e57e311dc
12 changed files with 56 additions and 5 deletions

View File

@@ -10,7 +10,8 @@ class Admin::VotationTypes::FieldsComponent < ApplicationComponent
def descriptions
{
unique: t("admin.polls.votation_type.unique_description"),
multiple: t("admin.polls.votation_type.multiple_description")
multiple: t("admin.polls.votation_type.multiple_description"),
open: t("admin.polls.votation_type.open_description")
}
end

View File

@@ -27,7 +27,7 @@ class Poll::Question < ApplicationRecord
accepts_nested_attributes_for :question_options, reject_if: :all_blank, allow_destroy: true
accepts_nested_attributes_for :votation_type
delegate :multiple?, :vote_type, to: :votation_type, allow_nil: true
delegate :multiple?, :open?, :vote_type, to: :votation_type, allow_nil: true
scope :sort_for_list, -> { order(Arel.sql("poll_questions.proposal_id IS NULL"), :created_at) }
scope :for_render, -> { includes(:author, :proposal) }

View File

@@ -3,7 +3,7 @@ class VotationType < ApplicationRecord
QUESTIONABLE_TYPES = %w[Poll::Question].freeze
enum :vote_type, { unique: 0, multiple: 1 }
enum :vote_type, { unique: 0, multiple: 1, open: 2 }
validates :questionable, presence: true
validates :questionable_type, inclusion: { in: ->(*) { QUESTIONABLE_TYPES }}