Sha256: eafdcf89de2f09971cdc6ba19d8b3b0bdd073a8ee3bcf8956cf411ca69927867
Contents?: true
Size: 844 Bytes
Versions: 5
Compression:
Stored size: 844 Bytes
Contents
module Comee module Core class Product < ApplicationRecord after_save :update_parent, if: proc { |product| product.parent && product.parent.leaf? } has_ancestry has_one_attached :thumbnail_image has_many_attached :images validates :code, presence: true, uniqueness: true validates :name, presence: true scope :leafs, -> { where(leaf: true) } def update_parent obj = parent obj.leaf = false obj.save! end def thumbnail_image_url thumbnail_image.attached? ? Rails.application.routes.url_helpers.rails_blob_url(thumbnail_image, only_path: false) : nil end def images_url images.attached? ? images.map { |image| Rails.application.routes.url_helpers.rails_blob_url(image, only_path: false) } : [] end end end end
Version data entries
5 entries across 5 versions & 1 rubygems