aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/redirector.rb
blob: b55f5e7bfc30543a5bd098eee39e87e9827a4f18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module ActionController
  class RedirectBackError < AbstractController::Error #:nodoc:
    DEFAULT_MESSAGE = 'No HTTP_REFERER was set in the request to this action, so redirect_to :back could not be called successfully. If this is a test, make sure to specify request.env["HTTP_REFERER"].'

    def initialize(message = nil)
      super(message || DEFAULT_MESSAGE)
    end
  end

  module Redirector
    extend ActiveSupport::Concern
    include AbstractController::Logger

    def redirect_to(url, status) #:doc:
      raise AbstractController::DoubleRenderError if response_body
      logger.info("Redirected to #{url}") if logger && logger.info?
      self.status = status
      self.location = url.gsub(/[\r\n]/, '')
      self.response_body = "<html><body>You are being <a href=\"#{ERB::Util.h(url)}\">redirected</a>.</body></html>"
    end
  end
end