Module: Redirectify

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/redirectify.rb

Instance Method Summary collapse

Instance Method Details

#back_or_default_path(default_path) ⇒ Object



8
9
10
# File 'app/controllers/concerns/redirectify.rb', line 8

def back_or_default_path(default_path)
  referer_path || default_path
end

#referer_pathObject



12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/concerns/redirectify.rb', line 12

def referer_path
  return if request.referer.blank?

  routing_hash = Rails.application.routes.recognize_path(request.referer)
  referer_uri = request.referer.dup.delete(['?', URI.parse(request.referer).query].join)

  request.referer if url_for(routing_hash) == referer_uri
rescue
  nil
end