Class ActionDispatch::Response
In: lib/action_dispatch/http/response.rb
Parent: Rack::Response

Represents an HTTP response generated by a controller action. One can use an ActionDispatch::Response object to retrieve the current state of the response, or customize the response. An Response object can either represent a "real" HTTP response (i.e. one that is meant to be sent back to the web browser) or a test response (i.e. one that is generated from integration tests). See CgiResponse and TestResponse, respectively.

Response is mostly a Ruby on Rails framework implement detail, and should never be used directly in controllers. Controllers should use the methods defined in ActionController::Base instead. For example, if you want to set the HTTP response‘s content MIME type, then use ActionControllerBase#headers instead of Response#headers.

Nevertheless, integration tests may want to inspect controller responses in more detail, and that‘s when Response can be useful for application developers. Integration test methods such as ActionDispatch::Integration::Session#get and ActionDispatch::Integration::Session#post return objects of type TestResponse (which are of course also of type Response).

For example, the following demo integration "test" prints the body of the controller response to the console:

 class DemoControllerTest < ActionDispatch::IntegrationTest
   def test_print_root_path_to_console
     get('/')
     puts @response.body
   end
 end

Methods

Included Modules

Setup ActionDispatch::Http::Cache::Response

Classes and Modules

Module ActionDispatch::Response::Setup

Constants

EMPTY = " "
CONTENT_TYPE = "Content-Type"

External Aliases

header= -> headers=

Attributes

blank  [RW] 
charset  [RW]  Sets the HTTP response‘s content MIME type. For example, in the controller you could write this:
 response.content_type = "text/plain"

If a character set has been defined for this response (see charset=) then the character set information will also be included in the content type information.

content_type  [RW]  Sets the HTTP response‘s content MIME type. For example, in the controller you could write this:
 response.content_type = "text/plain"

If a character set has been defined for this response (see charset=) then the character set information will also be included in the content type information.

header  [W] 
request  [RW] 
sending_file  [W] 

Public Instance methods

Returns a String to ensure compatibility with Net::HTTPResponse

Returns the response cookies, converted to a Hash of (name => value) pairs

  assert_equal 'AuthorOfNewPage', r.cookies['author']
prepare!()

Alias for to_a

redirect_url()

Alias for location

The response code of the request

status_message()

Alias for message

[Validate]