anyone-oslo/pages

View on GitHub
app/models/page_image.rb

Summary

Maintainability
A
0 mins
Test Coverage
C
78%
# frozen_string_literal: true

class PageImage < ApplicationRecord
  include PagesCore::Sweepable

  belongs_to :page
  belongs_to_image :image

  accepts_nested_attributes_for :image
  validates_associated :image

  acts_as_list scope: %i[page primary]

  localizable

  class << self
    def cleanup!
      find_each do |page_image|
        page_image.destroy unless page_image.image
      end
    end
  end

  def image
    super.localize!(locale)
  end
end