class Response
Ruby on Rails 7.2.3
Since v3.0.20Action Dispatch Response
Represents an HTTP response generated by a controller action. Use it to retrieve the current state of the response, or customize the response. It can either represent a real HTTP response (i.e. one that is meant to be sent back to the web browser) or a TestResponse (i.e. one that is generated from integration tests).
The Response object for the current request is exposed on controllers as ActionController::Metal#response. ActionController::Metal also provides a few additional methods that delegate to attributes of the Response such as ActionController::Metal#headers.
Integration tests will likely also want to inspect responses in more detail. Methods such as Integration::RequestHelpers#get and Integration::RequestHelpers#post return instances of TestResponse (which inherits from Response) for this purpose.
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
Inherits from
Namespace
Classes
Includes
Constants
- ActionDispatch::Response::CONTENT_TYPE
- ActionDispatch::Response::ContentTypeHeader
- ActionDispatch::Response::CONTENT_TYPE_PARSER
- ActionDispatch::Response::Header
- ActionDispatch::Response::Headers
- ActionDispatch::Response::NO_CONTENT_CODES
- ActionDispatch::Response::NullContentTypeHeader
- ActionDispatch::Response::SET_COOKIE
Attributes
Methods (defined here)
- # abort
- # await_commit
- # await_sent
- # body
- # body=
- # body_parts
- # charset
- # charset=
- # close
- # code
- # commit!
- # committed?
- # content_type
- # content_type=
- # cookies
- # delete_header
- # each
- # get_header
- # has_header?
- # location
- # location=
- # media_type
- # message
- # prepare!
- # redirect_url
- # reset_body!
- # response_code
- # send_file
- # sending!
- # sending?
- # sending_file=
- # sent!
- # sent?
- # set_header
- # status=
- # status_message
- # to_a
- # write
- self. create
- self. merge_default_headers
- self. new
Private methods
(10)
Implementation detail — not part of the public API.
Used by
Subclasses (1)
Methods (inherited)
From ActionDispatch::Http::Cache::Response (12)
- # date
- # date=
- # date?
- # etag=
- # etag?
- # last_modified
- # last_modified=
- # last_modified?
- # strong_etag=
- # strong_etag?
- # weak_etag=
- # weak_etag?
From Object (17)
- # acts_like?
- # blank?
- # deep_dup
- # duplicable?
- # html_safe?
- # in?
- # instance_values
- # instance_variable_names
- # presence
- # presence_in
- # present?
- # to_param
- # to_query
- # try
- # try!
- # with
- # with_options
From ActiveSupport::NumericWithFormat (2)
- # to_formatted_s
- # to_fs