Sha256: eded9400dab2a8e9b4e3711c82bdc53309efee76b26129dc9f79fec28c41cd25
Contents?: true
Size: 1.24 KB
Versions: 5
Compression:
Stored size: 1.24 KB
Contents
# frozen_string_literal: true module Decidim module Admin # A form object to create or update pages. class StaticPageForm < Form include TranslatableAttributes attribute :slug, String translatable_attribute :title, String translatable_attribute :content, String attribute :changed_notably, Boolean attribute :show_in_footer, Boolean attribute :weight, Integer attribute :topic_id, Integer mimic :static_page validates :slug, presence: true validates :title, :content, translatable_presence: true validates :slug, format: { with: /\A[a-z0-9-]+/ } validate :slug, :slug_uniqueness alias organization current_organization def slug super.to_s.downcase end def topic @topic ||= StaticPageTopic.find_by( organization: organization, id: topic_id ) end def topics @topics ||= StaticPageTopic.where( organization: current_organization ) end private def slug_uniqueness return unless organization return unless organization.static_pages.where(slug: slug).where.not(id: id).any? errors.add(:slug, :taken) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems