Skip to content

Commit 0a48f49

Browse files
Merge pull request rails#45362 from skipkayhil/docs-metal-headers
Fix docs for ActionController::Metal#headers
2 parents a108a5c + ab31e83 commit 0a48f49

File tree

3 files changed

+38
-29
lines changed

3 files changed

+38
-29
lines changed

actionpack/lib/action_controller/base.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,22 +167,6 @@ module ActionController
167167
class Base < Metal
168168
abstract!
169169

170-
# We document the request and response methods here because albeit they are
171-
# implemented in ActionController::Metal, the type of the returned objects
172-
# is unknown at that level.
173-
174-
##
175-
# :method: request
176-
#
177-
# Returns an ActionDispatch::Request instance that represents the
178-
# current request.
179-
180-
##
181-
# :method: response
182-
#
183-
# Returns an ActionDispatch::Response that represents the current
184-
# response.
185-
186170
# Shortcut helper that returns all the modules included in
187171
# ActionController::Base except the ones passed as arguments:
188172
#

actionpack/lib/action_controller/metal.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,25 @@ def controller_name
142142
self.class.controller_name
143143
end
144144

145-
attr_internal :response, :request
145+
##
146+
# :attr_reader: request
147+
#
148+
# The ActionDispatch::Request instance for the current request.
149+
attr_internal :request
150+
151+
##
152+
# :attr_reader: response
153+
#
154+
# The ActionDispatch::Response instance for the current response.
155+
attr_internal :response
156+
146157
delegate :session, to: "@_request"
147-
delegate :headers, :status=, :location=, :content_type=,
158+
159+
##
160+
# Delegates to ActionDispatch::Response#headers.
161+
delegate :headers, to: "@_response"
162+
163+
delegate :status=, :location=, :content_type=,
148164
:status, :location, :content_type, :media_type, to: "@_response"
149165

150166
def initialize

actionpack/lib/action_dispatch/http/response.rb

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ module ActionDispatch # :nodoc:
1212
# back to the web browser) or a TestResponse (i.e. one that is generated
1313
# from integration tests).
1414
#
15-
# \Response is mostly a Ruby on \Rails framework implementation detail, and
16-
# should never be used directly in controllers. Controllers should use the
17-
# methods defined in ActionController::Base instead. For example, if you want
18-
# to set the HTTP response's content MIME type, then use
19-
# ActionControllerBase#headers instead of Response#headers.
15+
# The \Response object for the current request is exposed on controllers as
16+
# ActionController::Metal#response. ActionController::Metal also provides a
17+
# few additional methods that delegate to attributes of the \Response such as
18+
# ActionController::Metal#headers.
2019
#
21-
# Nevertheless, integration tests may want to inspect controller responses in
22-
# more detail, and that's when \Response can be useful for application
23-
# developers. Integration test methods such as
24-
# Integration::RequestHelpers#get and Integration::RequestHelpers#post return
25-
# objects of type TestResponse (which are of course also of type \Response).
20+
# Integration tests will likely also want to inspect responses in
21+
# more detail. Methods such as Integration::RequestHelpers#get
22+
# and Integration::RequestHelpers#post return instances of
23+
# TestResponse (which inherits from \Response) for this purpose.
2624
#
2725
# For example, the following demo integration test prints the body of the
2826
# controller response to the console:
@@ -63,7 +61,18 @@ def to_hash
6361
# The HTTP status code.
6462
attr_reader :status
6563

66-
# Get headers for this response.
64+
# The headers for the response.
65+
#
66+
# header["Content-Type"] # => "text/plain"
67+
# header["Content-Type"] = "application/json"
68+
# header["Content-Type"] # => "application/json"
69+
#
70+
# Also aliased as +headers+.
71+
#
72+
# headers["Content-Type"] # => "text/plain"
73+
# headers["Content-Type"] = "application/json"
74+
# headers["Content-Type"] # => "application/json"
75+
#
6776
attr_reader :header
6877

6978
alias_method :headers, :header

0 commit comments

Comments
 (0)