Sha256: 6b248b3810f06c66431098091f417e0e555189cef85a16bf44aa47725176f16b

Contents?: true

Size: 665 Bytes

Versions: 14

Compression:

Stored size: 665 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
    session[:location_history] = session[:location_history].sort.last(count).to_h
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rails-add_ons-2.0.1 app/concerns/resources_controller/location_history.rb
rails-add_ons-2.0.0 app/concerns/resources_controller/location_history.rb
rails-add_ons-1.5.2 app/concerns/resources_controller/location_history.rb
rails-add_ons-1.5.1 app/concerns/resources_controller/location_history.rb
rails-add_ons-1.5.0 app/concerns/resources_controller/location_history.rb
rails-add_ons-1.4.1 app/concerns/resources_controller/location_history.rb
rails-add_ons-1.4.0 app/concerns/resources_controller/location_history.rb
rails-add_ons-1.3.3 app/concerns/resources_controller/location_history.rb
rails-add_ons-1.3.2 app/concerns/resources_controller/location_history.rb
rails-add_ons-1.3.1 app/concerns/resources_controller/location_history.rb
rails-add_ons-1.3.0 app/concerns/resources_controller/location_history.rb
rails-add_ons-1.2.0 app/concerns/resources_controller/location_history.rb
rails-add_ons-1.1.0 app/concerns/resources_controller/location_history.rb
rails-add_ons-1.0.0 app/concerns/resources_controller/location_history.rb