Sha256: c15eb79cf4775f4b4f4dc8f64cd8b48de30585fe7df775a3b022da04a9ce99a3
Contents?: true
Size: 708 Bytes
Versions: 34
Compression:
Stored size: 708 Bytes
Contents
module Workarea module FeaturedProducts extend ActiveSupport::Concern included do field :product_ids, type: Array, default: [] before_validation :clean_product_ids index({ product_ids: 1 }) end def featured_products? product_ids.present? end def featured_product?(id) id.to_s.in?(product_ids) end def add_product(id) product_ids.prepend(id) save end def remove_product(id_to_remove) product_ids.reject! { |id| id == id_to_remove } save end private def clean_product_ids if product_ids.present? product_ids.reject!(&:blank?) product_ids.uniq! end end end end
Version data entries
34 entries across 34 versions & 1 rubygems