Sha256: 5a48596c04db80b899958529c6cdd3106fd774b86b8b7eb690772d2d8879eb79

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

module Effective
  class PageSection < ActiveRecord::Base
    attr_accessor :current_user

    # Not used
    belongs_to :owner, polymorphic: true, optional: true

    has_many_rich_texts
    has_one_attached :file

    log_changes if respond_to?(:log_changes)

    self.table_name = EffectivePages.page_sections_table_name.to_s

    effective_resource do
      name              :string       # Unique name of this page section

      title             :string
      caption           :string

      link_label        :string
      link_url          :string

      hint              :text

      timestamps
    end

    validates :name, presence: true, uniqueness: true
    validates :title, presence: true, length: { maximum: 255 }

    validates :link_url, presence: true, if: -> { link_label.present? }
    validates :link_url, absence: true, if: -> { link_label.blank? }

    scope :deep, -> { with_attached_file.includes(:rich_texts) }
    scope :sorted, -> { order(:name) }

    def to_s
      name.presence || 'page section'
    end

    # As per has_many_rich_texts
    def body
      rich_text_body
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
effective_pages-3.3.2 app/models/effective/page_section.rb
effective_pages-3.3.1 app/models/effective/page_section.rb