Module: Admin::PathHistory

Included in:
BaseController
Defined in:
app/controllers/concerns/admin/path_history.rb

Instance Method Summary collapse

Instance Method Details

#back_uriObject

Returns url of previous GET-request. Used for ‘cancel’ button.



20
21
22
# File 'app/controllers/concerns/admin/path_history.rb', line 20

def back_uri
  session[:prev_path] || '/admin'
end

#last_uriObject

Returns url of last GET-request. Used in #redirect_to_last method for redirection after clicking ‘destroy’ button on index pages. This is useful for pagination because client will be redirected on the same page he was.



27
28
29
# File 'app/controllers/concerns/admin/path_history.rb', line 27

def last_uri
  session[:last_path]
end

#no_cache!Object

To ensure correct path history working we need to be 100% sure that browser’s back button will not use cache



4
5
6
7
8
# File 'app/controllers/concerns/admin/path_history.rb', line 4

def no_cache!
  response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
  response.headers['Pragma'] = 'no-cache'
  response.headers['Expires'] = 'Fri, 01 Jan 1990 00:00:00 GMT'
end

#redirect_to_backObject



31
32
33
# File 'app/controllers/concerns/admin/path_history.rb', line 31

def redirect_to_back
  redirect_to back_uri
end

#redirect_to_lastObject



35
36
37
# File 'app/controllers/concerns/admin/path_history.rb', line 35

def redirect_to_last
  redirect_to last_uri
end

#store_path_historyObject

Stores history of GET-request urls. We don’t need to store POST or any other requests because we can’t use them for creating back buttons or redirection.



12
13
14
15
16
17
# File 'app/controllers/concerns/admin/path_history.rb', line 12

def store_path_history
  if !request.xhr? && request.method == 'GET' && session[:last_path] != request.fullpath
    session[:prev_path] = session[:last_path]
    session[:last_path] = request.fullpath
  end
end