Sha256: de4bd9c74e487c4f28f28564f4e9ee3005b8af8487f166a4a959d1253607d7d0

Contents?: true

Size: 662 Bytes

Versions: 24

Compression:

Stored size: 662 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Consultations
    class VoteForm < Form
      mimic :vote

      attribute :decidim_consultations_response_id, Integer

      validates :decidim_consultations_response_id, presence: true
      validate :response_exists

      def response
        @response ||= Response.find_by(id: decidim_consultations_response_id)
      end

      private

      def response_exists
        return unless response.nil?
        errors.add(
          :decidim_consultations_response_id,
          I18n.t("decidim_consultations_response_id.not_found", scope: "activemodel.errors.vote")
        )
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
decidim-consultations-0.18.1 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.17.2 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.18.0 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.17.1 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.16.1 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.17.0 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.16.0 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.15.2 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.15.1 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.15.0 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.14.4 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.14.3 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.14.2 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.14.1 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.13.1 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.12.2 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.13.0 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.12.1 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.13.0.pre1 app/forms/decidim/consultations/vote_form.rb
decidim-consultations-0.12.0 app/forms/decidim/consultations/vote_form.rb