Sha256: 7a0e9c89b529075bdd8c35ddbd3135c4354f39e61225dc98f2c4b5d19c0bb868

Contents?: true

Size: 1022 Bytes

Versions: 17

Compression:

Stored size: 1022 Bytes

Contents

# frozen_string_literal: true

class Comfy::Cms::Translation < ActiveRecord::Base

  self.table_name = "comfy_cms_translations"

  include Comfy::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

17 entries across 17 versions & 6 rubygems

Version Path
comfortable_mexican_sofa-2.0.19 app/models/comfy/cms/translation.rb
PixelForce_ETS-0.0.2 app/models/comfy/cms/translation.rb
PixelForce_ETS-0.0.1 app/models/comfy/cms/translation.rb
kcyEtsTest2-0.0.4 app/models/comfy/cms/translation.rb
kcyEtsTest2-0.0.3 app/models/comfy/cms/translation.rb
kcyEtsTest2-0.0.2 app/models/comfy/cms/translation.rb
kcyEtsTest2-0.0.1 app/models/comfy/cms/translation.rb
kcyEtsTest-0.0.1 app/models/comfy/cms/translation.rb
kcyEtsTest-2.2.19 app/models/comfy/cms/translation.rb
ComfortableMexicanSofa-2.0.18 app/models/comfy/cms/translation.rb
kcy1-1.0 app/models/comfy/cms/translation.rb
comfortable_mexican_sofa-2.0.18 app/models/comfy/cms/translation.rb
comfortable_mexican_sofa-2.0.17 app/models/comfy/cms/translation.rb
comfortable_mexican_sofa-2.0.16 app/models/comfy/cms/translation.rb
comfortable_mexican_sofa-2.0.15 app/models/comfy/cms/translation.rb
comfortable_mexican_sofa-2.0.14 app/models/comfy/cms/translation.rb
comfortable_mexican_sofa-2.0.13 app/models/comfy/cms/translation.rb