Class: CheckByRank

Inherits:
BasicWay show all
Defined in:
lib/product_home_template.rb

Instance Method Summary collapse

Methods inherited from BasicWay

#with_page, #without_page

Constructor Details

#initialize(param) ⇒ CheckByRank

this method initializes base class object with the store detail and an empty array to store the products by click history



55
56
57
58
# File 'lib/product_home_template.rb', line 55

def initialize(param)
    super(param)
    @record_products = []
end

Instance Method Details

#my_special_method(pages) ⇒ Object

this method to run the logic of sorting the products with pagination by ranking the click history



61
62
63
64
65
66
67
68
69
# File 'lib/product_home_template.rb', line 61

def my_special_method(pages)
    @sorted_click = current_member.clicks.order('id desc').select("product_identity").group_by{|o| o.product_identity}.keys.uniq
    @sorted_click.each do |c|
        if(@store_detail.products.find(c))
        @record_products << @store_detail.products.find(c).paginate(page: pages, per_page: 3).find(c)
        end
    end
    @record_products.take(3)
end

#my_special_method_without(member) ⇒ Object

this method to run the logic of sorting the products without pagination by ranking the click history



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/product_home_template.rb', line 72

def my_special_method_without(member)
    @sorted_click = member.clicks.order('id desc').select("product_identity").group_by{|o| o.product_identity}.keys.uniq
    @sorted_click.each do |c|
        if(@store_detail.products.find(c))
        @record_products << @store_detail.products.find(c)
        end
    end
    puts("=== by rank ===")
    puts(@record_products)
    return @record_products.take(3)
end