Module: Gemgento::CategoriesHelper
- Defined in:
- app/helpers/gemgento/categories_helper.rb
Instance Method Summary collapse
-
#cache_key ⇒ Array
Cache key values for categories#show fragment cache.
-
#filter_options(attribute) ⇒ Array(String)
Get a list of values for a given attribute.
-
#query_params_cache_keys ⇒ Array(String)
Cache key values from query string.
Instance Method Details
#cache_key ⇒ Array
Cache key values for categories#show fragment cache.
23 24 25 26 27 28 29 30 |
# File 'app/helpers/gemgento/categories_helper.rb', line 23 def cache_key cache_key = [@current_category] cache_key << user_signed_in? ? current_user.user_group : nil cache_key << @products.maximum(:cache_expires_at) if @products cache_key += query_params_cache_keys return cache_key end |
#filter_options(attribute) ⇒ Array(String)
Get a list of values for a given attribute. Values are based on all filters except the filter for the given attribute.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/gemgento/categories_helper.rb', line 8 def (attribute) filters = @filters.select{ |f| (f[:attribute].is_a?(Array) ? f[:attribute].first[:code] : f[:attribute].code) != attribute.to_s } products = Gemgento::Product.active.catalog_visible .joins(:product_categories) .where('gemgento_product_categories.category_id = ?', @current_category.id) products = products.filter(filters) if filters.any? = products.map(&attribute) .uniq.reject(&:blank?).sort end |
#query_params_cache_keys ⇒ Array(String)
Cache key values from query string.
35 36 37 |
# File 'app/helpers/gemgento/categories_helper.rb', line 35 def query_params_cache_keys [params[:page]] end |