class CheckByRank
Public Class Methods
new(param)
click to toggle source
this method initializes base class object with the store detail and an empty array to store the products by click history
Calls superclass method
BasicWay::new
# File lib/product_home_template.rb, line 55 def initialize(param) super(param) @record_products = [] end
Public Instance Methods
my_special_method(pages)
click to toggle source
this method to run the logic of sorting the products with pagination by ranking the click history
# 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_by(id: 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)
click to toggle source
this method to run the logic of sorting the products without pagination by ranking the click history
# 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_by(id: c)) @record_products << @store_detail.products.find(c) end end puts("=== by rank ===") puts(@record_products) return @record_products.take(3) end