Exception: Sidewalk::SeeOtherRedirect

Inherits:
Redirect show all
Defined in:
lib/sidewalk/redirect.rb

Overview

Use if the resource hasn’t moved, but you want to redirect anyway.

The new request will be a GET request.

Standard usage is to redirect after a POST, to make the browser’s Refresh and back/forward buttons work as expected.

Defaults to a ‘303 See Other’, but if you need to support pre-HTTP/1.1 browsers, you might want to change this.

Examples:

Supporting Legacy Browsers

Instance Attribute Summary

Attributes inherited from Redirect

#url

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ SeeOtherRedirect

Returns a new instance of SeeOtherRedirect.



49
50
51
# File 'lib/sidewalk/redirect.rb', line 49

def initialize url
  super url, nil, nil
end

Instance Method Details

#description(request) ⇒ Object

Return an appropriate description.



69
70
71
72
73
74
75
76
# File 'lib/sidewalk/redirect.rb', line 69

def description request
  case status(request)
  when 303
    'See Other'
  when 302
    'Found'
  end
end

#status(request) ⇒ Object

Return an appropriate status code.

Returns:

  • 303 for HTTP/1.1 clients

  • 302 for HTTP/1.0 clients



57
58
59
60
61
62
63
# File 'lib/sidewalk/redirect.rb', line 57

def status request
  if request.http_version == '1.1'
    303
  else
    302
  end
end