class Response
Ruby on Rails 7.0.10
Since v3.0.20Represents 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).
Response is mostly a Ruby on Rails framework implementation 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 Integration::RequestHelpers#get and Integration::RequestHelpers#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
Inherits from
Namespace
Classes
Includes
Constants
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?
- # media_type
- # message
- # prepare!
- # 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 (16)
- # 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_options
From ActiveRecord::TestFixtures (4)
From ActiveSupport::Concern (3)
- # class_methods
- # included
- # prepended