Sha256: 777dcd81b94c9962d87cbe2cc762630b0d9e4733e2238ee750c91790321c9b2c

Contents?: true

Size: 1022 Bytes

Versions: 2

Compression:

Stored size: 1022 Bytes

Contents

# frozen_string_literal: true
module Decidim
  module Admin
    # A form object used to create participatory processes from the admin
    # dashboard.
    #
    class ParticipatoryProcessForm < Rectify::Form
      include TranslatableAttributes

      translatable_attribute :title, String
      translatable_attribute :subtitle, String
      translatable_attribute :description, String
      translatable_attribute :short_description, String

      mimic :participatory_process

      attribute :slug, String
      attribute :hashtag, String

      validates :slug, presence: true
      translatable_validates :title, :subtitle, :description, :short_description, presence: true

      validate :slug, :slug_uniqueness

      private

      def slug_uniqueness
        return unless ParticipatoryProcess.where(slug: slug).where.not(id: id).any?

        errors.add(
          :slug,
          I18n.t("models.participatory_process.validations.slug_uniqueness", scope: "decidim.admin")
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
decidim-admin-0.0.1.alpha5 app/forms/decidim/admin/participatory_process_form.rb
decidim-0.0.1.alpha5 decidim-admin/app/forms/decidim/admin/participatory_process_form.rb