Class: Comee::Core::Product

Inherits:
ApplicationRecord show all
Defined in:
app/models/comee/core/product.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ransackable_associations(_auth_object = nil) ⇒ Object



38
39
40
# File 'app/models/comee/core/product.rb', line 38

def self.ransackable_associations(_auth_object = nil)
  []
end

.ransackable_attributes(_auth_object = nil) ⇒ Object



34
35
36
# File 'app/models/comee/core/product.rb', line 34

def self.ransackable_attributes(_auth_object = nil)
  %w[id code name description customs_description leaf]
end

Instance Method Details

#default_unitObject



42
43
44
# File 'app/models/comee/core/product.rb', line 42

def default_unit
  preferred_units.find { |unit| unit["default"] }
end

#images_urlObject



30
31
32
# File 'app/models/comee/core/product.rb', line 30

def images_url
  images.attached? ? images.map { |image| Rails.application.routes.url_helpers.rails_blob_url(image, only_path: false) } : []
end

#thumbnail_image_urlObject



26
27
28
# File 'app/models/comee/core/product.rb', line 26

def thumbnail_image_url
  thumbnail_image.attached? ? Rails.application.routes.url_helpers.rails_blob_url(thumbnail_image, only_path: false) : nil
end

#update_parentObject



20
21
22
23
24
# File 'app/models/comee/core/product.rb', line 20

def update_parent
  obj = parent
  obj.leaf = false
  obj.save!
end