module Backtrail::BaseController

Public Instance Methods

previous_path() click to toggle source
# File lib/backtrail/controllers.rb, line 10
def previous_path
  get_from_stack_path || backtrail_starting_point
end

Protected Instance Methods

backtrail_starting_point() click to toggle source
# File lib/backtrail/controllers.rb, line 42
def backtrail_starting_point
  root_path
end
get_from_stack_path() click to toggle source
# File lib/backtrail/controllers.rb, line 35
def get_from_stack_path
  if params[:trail] == 'back'
    session['previous_paths'].try(:pop)
  end
  session['previous_paths'].try(:last)
end
update_previous_paths() click to toggle source
# File lib/backtrail/controllers.rb, line 16
def update_previous_paths
  current = request.url.split('?')[0]
  if request.get? and !request.xhr?
    if session['_referer'].present? and !params[:trail]
      previous = session['_referer']
      if session['previous_paths'].nil?
        session['previous_paths'] = []
      end
      if session['previous_paths'].length == 5
        session['previous_paths'].delete_at 0
      end
      if previous != current
        session['previous_paths'].push previous
      end
    end
    session['_referer'] = current
  end
end