Sha256: adc3be3d136dd99d9678e5fce6ed3fb89435dfee5144d8074958719061ae09cc

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

class Occams::Cms::Translation < ActiveRecord::Base

  self.table_name = "occams_cms_translations"

  include Occams::Cms::WithFragments

  cms_has_revisions_for :fragments_attributes

  delegate :site, to: :page

  # -- Relationships -----------------------------------------------------------
  belongs_to :page

  # -- Callbacks ---------------------------------------------------------------
  before_validation :assign_layout

  # -- Scopes ------------------------------------------------------------------
  scope :published, -> { where(is_published: true) }

  # -- Validations -------------------------------------------------------------
  validates :label,
    presence:   true

  validates :locale,
    presence:   true,
    uniqueness: { scope: :page_id }

  validate :validate_locale

private

  def validate_locale
    return unless page
    errors.add(:locale) if locale == page.site.locale
  end

  def assign_layout
    self.layout ||= page.layout if page.present?
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
occams-1.0.0 app/models/occams/cms/translation.rb