Sha256: c0fbe95fb7b8cc955a1ad4af75012ee0012c2b05ef84db3bf75acf060fe40ddc

Contents?: true

Size: 589 Bytes

Versions: 11

Compression:

Stored size: 589 Bytes

Contents

module Effective
  class PollQuestionOption < ActiveRecord::Base
    belongs_to :poll_question

    effective_resource do
      title         :text
      position      :integer

      timestamps
    end

    before_validation(if: -> { poll_question.present? }) do
      self.position ||= (poll_question.poll_question_options.map { |obj| obj.position }.compact.max || -1) + 1
    end

    scope :sorted, -> { order(:position) }

    validates :title, presence: true
    validates :position, presence: true

    def to_s
      title.presence || 'New Poll Question Option'
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
effective_polls-0.3.0 app/models/effective/poll_question_option.rb
effective_polls-0.2.0 app/models/effective/poll_question_option.rb
effective_polls-0.1.6 app/models/effective/poll_question_option.rb
effective_polls-0.1.5 app/models/effective/poll_question_option.rb
effective_polls-0.1.4 app/models/effective/poll_question_option.rb
effective_polls-0.1.3 app/models/effective/poll_question_option.rb
effective_polls-0.1.2 app/models/effective/poll_question_option.rb
effective_polls-0.1.1 app/models/effective/poll_question_option.rb
effective_polls-0.1.0 app/models/effective/poll_question_option.rb
effective_polls-0.0.2 app/models/effective/poll_question_option.rb
effective_polls-0.0.1 app/models/effective/poll_question_option.rb