Sha256: 8c292f7f4b07e77424ca88cd55a0242daf93639af9fda2b5618f952663278954
Contents?: true
Size: 1.34 KB
Versions: 80
Compression:
Stored size: 1.34 KB
Contents
module Comee module Core class Product < ApplicationRecord after_save :update_parent, if: proc { |product| product.parent && product.parent.leaf? } has_ancestry has_many :product_lookups has_one_attached :thumbnail_image has_many_attached :images belongs_to :source, class_name: "Comee::Core::FulfillmentCenter", optional: true belongs_to :weight_unit, class_name: "Comee::Core::Unit", optional: true validates :code, presence: true, uniqueness: true validates :name, :customs_description, 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 def self.ransackable_attributes(_auth_object = nil) %w[id code name description customs_description leaf] end def self.ransackable_associations(_auth_object = nil) [] end def default_unit preferred_units.find { |unit| unit["default"] } end end end end
Version data entries
80 entries across 80 versions & 1 rubygems