Sha256: 4d36cc8b63b8871a1e1d0c19ce2494fde3ce383dd93382796b6826e7eca6a239

Contents?: true

Size: 1016 Bytes

Versions: 4

Compression:

Stored size: 1016 Bytes

Contents

# frozen_string_literal: true
module Decidim
  module Admin
    # A form object used to create participatory processes from the admin
    # dashboard.
    #
    class ParticipatoryProcessForm < 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
      attribute :promoted, Boolean
      attribute :hero_image
      attribute :banner_image

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

      validate :slug, :slug_uniqueness

      private

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

        errors.add(:slug, :taken)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

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