Sha256: b19f3a2cbaf6323f5209f5808ad90d7c41c31e102c4f0d9e4e8e00adcd770e7e

Contents?: true

Size: 656 Bytes

Versions: 1

Compression:

Stored size: 656 Bytes

Contents

module Tasuku
  module Concerns::Models::Taskables::Question
    extend ActiveSupport::Concern

    included do
      include ::Tasks::Taskables::Taskable
      include ::Tasks::Concerns::Illustratable

      has_many :options
      has_many :votes, through: :options

      accepts_nested_attributes_for :options, allow_destroy: true

      def answers
        Taskables::Question::Answer.joins(:votes).where(
          Taskables::Question::Vote.table_name => { option_id: options.pluck(:id) }
        ).uniq
      end

      def single?
        !multiple?
      end

      def to_s
        text
      end

      responses are: :answers
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tasuku-0.1.0 lib/tasuku/concerns/models/taskables/question.rb