Class: ActionController::AbstractResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/action_controller/response.rb

Overview

:nodoc:

Direct Known Subclasses

CgiResponse, TestResponse

Constant Summary collapse

DEFAULT_HEADERS =
{ "Cache-Control" => "no-cache" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAbstractResponse

Returns a new instance of AbstractResponse.



6
7
8
# File 'lib/action_controller/response.rb', line 6

def initialize
  @body, @headers, @session, @assigns = "", DEFAULT_HEADERS.merge("cookie" => []), [], []
end

Instance Attribute Details

#assignsObject

Returns the value of attribute assigns.



4
5
6
# File 'lib/action_controller/response.rb', line 4

def assigns
  @assigns
end

#bodyObject

Returns the value of attribute body.



4
5
6
# File 'lib/action_controller/response.rb', line 4

def body
  @body
end

#cookiesObject

Returns the value of attribute cookies.



4
5
6
# File 'lib/action_controller/response.rb', line 4

def cookies
  @cookies
end

#headersObject

Returns the value of attribute headers.



4
5
6
# File 'lib/action_controller/response.rb', line 4

def headers
  @headers
end

#layoutObject

Returns the value of attribute layout.



4
5
6
# File 'lib/action_controller/response.rb', line 4

def layout
  @layout
end

#redirected_toObject

Returns the value of attribute redirected_to.



4
5
6
# File 'lib/action_controller/response.rb', line 4

def redirected_to
  @redirected_to
end

#redirected_to_method_paramsObject

Returns the value of attribute redirected_to_method_params.



4
5
6
# File 'lib/action_controller/response.rb', line 4

def redirected_to_method_params
  @redirected_to_method_params
end

#sessionObject

Returns the value of attribute session.



4
5
6
# File 'lib/action_controller/response.rb', line 4

def session
  @session
end

#templateObject

Returns the value of attribute template.



4
5
6
# File 'lib/action_controller/response.rb', line 4

def template
  @template
end

Instance Method Details

#charsetObject



23
24
25
26
# File 'lib/action_controller/response.rb', line 23

def charset
  charset = String(@headers["Content-Type"]).split(";")[1]
  charset.blank? ? nil : charset.strip.split("=")[1]
end

#charset=(encoding) ⇒ Object



19
20
21
# File 'lib/action_controller/response.rb', line 19

def charset=(encoding)
  @headers["Content-Type"] = "#{content_type || "text/html"}; charset=#{encoding}"
end

#content_typeObject



14
15
16
17
# File 'lib/action_controller/response.rb', line 14

def content_type
  content_type = String(@headers["Content-Type"]).split(";")[0]
  content_type.blank? ? nil : content_type
end

#content_type=(mime_type) ⇒ Object



10
11
12
# File 'lib/action_controller/response.rb', line 10

def content_type=(mime_type)
  @headers["Content-Type"] = charset ? "#{mime_type}; charset=#{charset}" : mime_type
end

#redirect(to_url, permanently = false) ⇒ Object



28
29
30
31
32
33
# File 'lib/action_controller/response.rb', line 28

def redirect(to_url, permanently = false)
  @headers["Status"]   = "302 Found" unless @headers["Status"] == "301 Moved Permanently"
  @headers["Location"] = to_url

  @body = "<html><body>You are being <a href=\"#{to_url}\">redirected</a>.</body></html>"
end