Sha256: 1ea482560bd06304ce6eae3069531a3a5719ee3c0edb57d432187a1cab7c5e37
Contents?: true
Size: 820 Bytes
Versions: 3
Compression:
Stored size: 820 Bytes
Contents
module ResourcesController::LocationHistory extend ActiveSupport::Concern included do if respond_to?(:before_action) before_action :store_location else before_filter :store_location end end private def store_location truncate_location_history(9) location_history[Time.zone.now] = request.referer end def location_history session[:location_history] ||= {} end def last_location location_history.sort.last.try(:last) end def truncate_location_history(count = 0) return if location_history.size <= count truncated = session[:location_history].sort.last(count) session[:location_history] = if truncated.respond_to?(:to_h) truncated.to_h else truncated.each_with_object({}) { |a, hash| hash[a.first] = a.last } end end end
Version data entries
3 entries across 3 versions & 1 rubygems