actionpack 7.1.5.1 → 7.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +61 -642
- data/lib/abstract_controller/asset_paths.rb +2 -0
- data/lib/abstract_controller/base.rb +102 -98
- data/lib/abstract_controller/caching/fragments.rb +50 -53
- data/lib/abstract_controller/caching.rb +2 -0
- data/lib/abstract_controller/callbacks.rb +66 -64
- data/lib/abstract_controller/collector.rb +6 -6
- data/lib/abstract_controller/deprecator.rb +2 -0
- data/lib/abstract_controller/error.rb +2 -0
- data/lib/abstract_controller/helpers.rb +70 -85
- data/lib/abstract_controller/logger.rb +2 -0
- data/lib/abstract_controller/railties/routes_helpers.rb +2 -0
- data/lib/abstract_controller/rendering.rb +13 -12
- data/lib/abstract_controller/translation.rb +12 -13
- data/lib/abstract_controller/url_for.rb +8 -6
- data/lib/abstract_controller.rb +2 -0
- data/lib/action_controller/api/api_rendering.rb +2 -0
- data/lib/action_controller/api.rb +74 -72
- data/lib/action_controller/base.rb +155 -117
- data/lib/action_controller/caching.rb +15 -12
- data/lib/action_controller/deprecator.rb +2 -0
- data/lib/action_controller/form_builder.rb +20 -17
- data/lib/action_controller/log_subscriber.rb +3 -1
- data/lib/action_controller/metal/allow_browser.rb +119 -0
- data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
- data/lib/action_controller/metal/conditional_get.rb +188 -174
- data/lib/action_controller/metal/content_security_policy.rb +25 -24
- data/lib/action_controller/metal/cookies.rb +4 -2
- data/lib/action_controller/metal/data_streaming.rb +64 -55
- data/lib/action_controller/metal/default_headers.rb +5 -3
- data/lib/action_controller/metal/etag_with_flash.rb +3 -1
- data/lib/action_controller/metal/etag_with_template_digest.rb +17 -15
- data/lib/action_controller/metal/exceptions.rb +11 -9
- data/lib/action_controller/metal/flash.rb +12 -10
- data/lib/action_controller/metal/head.rb +12 -10
- data/lib/action_controller/metal/helpers.rb +63 -55
- data/lib/action_controller/metal/http_authentication.rb +214 -203
- data/lib/action_controller/metal/implicit_render.rb +17 -15
- data/lib/action_controller/metal/instrumentation.rb +15 -12
- data/lib/action_controller/metal/live.rb +113 -107
- data/lib/action_controller/metal/logging.rb +6 -4
- data/lib/action_controller/metal/mime_responds.rb +151 -142
- data/lib/action_controller/metal/parameter_encoding.rb +34 -32
- data/lib/action_controller/metal/params_wrapper.rb +57 -59
- data/lib/action_controller/metal/permissions_policy.rb +13 -12
- data/lib/action_controller/metal/rate_limiting.rb +62 -0
- data/lib/action_controller/metal/redirecting.rb +108 -82
- data/lib/action_controller/metal/renderers.rb +50 -49
- data/lib/action_controller/metal/rendering.rb +103 -75
- data/lib/action_controller/metal/request_forgery_protection.rb +162 -133
- data/lib/action_controller/metal/rescue.rb +11 -9
- data/lib/action_controller/metal/streaming.rb +138 -136
- data/lib/action_controller/metal/strong_parameters.rb +483 -478
- data/lib/action_controller/metal/testing.rb +2 -0
- data/lib/action_controller/metal/url_for.rb +17 -15
- data/lib/action_controller/metal.rb +58 -57
- data/lib/action_controller/railtie.rb +3 -0
- data/lib/action_controller/railties/helpers.rb +2 -0
- data/lib/action_controller/renderer.rb +42 -36
- data/lib/action_controller/template_assertions.rb +4 -2
- data/lib/action_controller/test_case.rb +146 -126
- data/lib/action_controller.rb +5 -1
- data/lib/action_dispatch/constants.rb +2 -0
- data/lib/action_dispatch/deprecator.rb +2 -0
- data/lib/action_dispatch/http/cache.rb +27 -26
- data/lib/action_dispatch/http/content_disposition.rb +2 -0
- data/lib/action_dispatch/http/content_security_policy.rb +48 -59
- data/lib/action_dispatch/http/filter_parameters.rb +13 -14
- data/lib/action_dispatch/http/filter_redirect.rb +15 -1
- data/lib/action_dispatch/http/headers.rb +22 -22
- data/lib/action_dispatch/http/mime_negotiation.rb +30 -41
- data/lib/action_dispatch/http/mime_type.rb +25 -21
- data/lib/action_dispatch/http/mime_types.rb +2 -0
- data/lib/action_dispatch/http/parameters.rb +11 -9
- data/lib/action_dispatch/http/permissions_policy.rb +26 -36
- data/lib/action_dispatch/http/rack_cache.rb +2 -0
- data/lib/action_dispatch/http/request.rb +75 -95
- data/lib/action_dispatch/http/response.rb +61 -61
- data/lib/action_dispatch/http/upload.rb +18 -16
- data/lib/action_dispatch/http/url.rb +75 -73
- data/lib/action_dispatch/journey/formatter.rb +13 -6
- data/lib/action_dispatch/journey/gtg/builder.rb +4 -3
- data/lib/action_dispatch/journey/gtg/simulator.rb +2 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +10 -8
- data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
- data/lib/action_dispatch/journey/nodes/node.rb +6 -5
- data/lib/action_dispatch/journey/parser.rb +4 -3
- data/lib/action_dispatch/journey/parser_extras.rb +2 -0
- data/lib/action_dispatch/journey/path/pattern.rb +4 -1
- data/lib/action_dispatch/journey/route.rb +9 -7
- data/lib/action_dispatch/journey/router/utils.rb +16 -15
- data/lib/action_dispatch/journey/router.rb +4 -2
- data/lib/action_dispatch/journey/routes.rb +4 -2
- data/lib/action_dispatch/journey/scanner.rb +4 -2
- data/lib/action_dispatch/journey/visitors.rb +2 -0
- data/lib/action_dispatch/journey.rb +2 -0
- data/lib/action_dispatch/log_subscriber.rb +2 -0
- data/lib/action_dispatch/middleware/actionable_exceptions.rb +2 -0
- data/lib/action_dispatch/middleware/assume_ssl.rb +8 -5
- data/lib/action_dispatch/middleware/callbacks.rb +3 -1
- data/lib/action_dispatch/middleware/cookies.rb +119 -104
- data/lib/action_dispatch/middleware/debug_exceptions.rb +13 -5
- data/lib/action_dispatch/middleware/debug_locks.rb +15 -13
- data/lib/action_dispatch/middleware/debug_view.rb +2 -0
- data/lib/action_dispatch/middleware/exception_wrapper.rb +6 -11
- data/lib/action_dispatch/middleware/executor.rb +2 -0
- data/lib/action_dispatch/middleware/flash.rb +63 -51
- data/lib/action_dispatch/middleware/host_authorization.rb +17 -15
- data/lib/action_dispatch/middleware/public_exceptions.rb +8 -6
- data/lib/action_dispatch/middleware/reloader.rb +5 -3
- data/lib/action_dispatch/middleware/remote_ip.rb +77 -72
- data/lib/action_dispatch/middleware/request_id.rb +14 -9
- data/lib/action_dispatch/middleware/server_timing.rb +4 -2
- data/lib/action_dispatch/middleware/session/abstract_store.rb +2 -0
- data/lib/action_dispatch/middleware/session/cache_store.rb +13 -8
- data/lib/action_dispatch/middleware/session/cookie_store.rb +27 -26
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +7 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +16 -16
- data/lib/action_dispatch/middleware/ssl.rb +43 -40
- data/lib/action_dispatch/middleware/stack.rb +11 -10
- data/lib/action_dispatch/middleware/static.rb +33 -31
- data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +1 -1
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +1 -1
- data/lib/action_dispatch/railtie.rb +2 -3
- data/lib/action_dispatch/request/session.rb +23 -21
- data/lib/action_dispatch/request/utils.rb +2 -0
- data/lib/action_dispatch/routing/endpoint.rb +2 -0
- data/lib/action_dispatch/routing/inspector.rb +6 -4
- data/lib/action_dispatch/routing/mapper.rb +623 -625
- data/lib/action_dispatch/routing/polymorphic_routes.rb +69 -62
- data/lib/action_dispatch/routing/redirection.rb +37 -32
- data/lib/action_dispatch/routing/route_set.rb +60 -46
- data/lib/action_dispatch/routing/routes_proxy.rb +6 -4
- data/lib/action_dispatch/routing/url_for.rb +130 -125
- data/lib/action_dispatch/routing.rb +150 -148
- data/lib/action_dispatch/system_test_case.rb +91 -81
- data/lib/action_dispatch/system_testing/browser.rb +4 -2
- data/lib/action_dispatch/system_testing/driver.rb +2 -0
- data/lib/action_dispatch/system_testing/server.rb +2 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +32 -21
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
- data/lib/action_dispatch/testing/assertion_response.rb +8 -6
- data/lib/action_dispatch/testing/assertions/response.rb +26 -23
- data/lib/action_dispatch/testing/assertions/routing.rb +153 -84
- data/lib/action_dispatch/testing/assertions.rb +2 -0
- data/lib/action_dispatch/testing/integration.rb +223 -222
- data/lib/action_dispatch/testing/request_encoder.rb +2 -0
- data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
- data/lib/action_dispatch/testing/test_process.rb +12 -8
- data/lib/action_dispatch/testing/test_request.rb +3 -1
- data/lib/action_dispatch/testing/test_response.rb +27 -26
- data/lib/action_dispatch.rb +22 -32
- data/lib/action_pack/gem_version.rb +6 -4
- data/lib/action_pack/version.rb +3 -1
- data/lib/action_pack.rb +17 -16
- metadata +33 -16
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# :markup: markdown
|
4
|
+
|
3
5
|
require "set"
|
4
6
|
|
5
7
|
module ActionController
|
@@ -13,7 +15,7 @@ module ActionController
|
|
13
15
|
Renderers.remove(key)
|
14
16
|
end
|
15
17
|
|
16
|
-
# See
|
18
|
+
# See `Responder#api_behavior`
|
17
19
|
class MissingRenderer < LoadError
|
18
20
|
def initialize(format)
|
19
21
|
super "No renderer defined for format: #{format}"
|
@@ -24,7 +26,7 @@ module ActionController
|
|
24
26
|
extend ActiveSupport::Concern
|
25
27
|
|
26
28
|
# A Set containing renderer names that correspond to available renderer procs.
|
27
|
-
# Default values are
|
29
|
+
# Default values are `:json`, `:js`, `:xml`.
|
28
30
|
RENDERERS = Set.new
|
29
31
|
|
30
32
|
included do
|
@@ -42,35 +44,34 @@ module ActionController
|
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
|
-
# Adds a new renderer to call within controller actions.
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# hash of options passed to +render+.
|
47
|
+
# Adds a new renderer to call within controller actions. A renderer is invoked
|
48
|
+
# by passing its name as an option to AbstractController::Rendering#render. To
|
49
|
+
# create a renderer pass it a name and a block. The block takes two arguments,
|
50
|
+
# the first is the value paired with its key and the second is the remaining
|
51
|
+
# hash of options passed to `render`.
|
51
52
|
#
|
52
53
|
# Create a csv renderer:
|
53
54
|
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
55
|
+
# ActionController::Renderers.add :csv do |obj, options|
|
56
|
+
# filename = options[:filename] || 'data'
|
57
|
+
# str = obj.respond_to?(:to_csv) ? obj.to_csv : obj.to_s
|
58
|
+
# send_data str, type: Mime[:csv],
|
59
|
+
# disposition: "attachment; filename=#{filename}.csv"
|
60
|
+
# end
|
60
61
|
#
|
61
|
-
# Note that we used Mime
|
62
|
+
# Note that we used [Mime](:csv) for the csv mime type as it comes with Rails.
|
62
63
|
# For a custom renderer, you'll need to register a mime type with
|
63
|
-
#
|
64
|
+
# `Mime::Type.register`.
|
64
65
|
#
|
65
66
|
# To use the csv renderer in a controller action:
|
66
67
|
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
68
|
+
# def show
|
69
|
+
# @csvable = Csvable.find(params[:id])
|
70
|
+
# respond_to do |format|
|
71
|
+
# format.html
|
72
|
+
# format.csv { render csv: @csvable, filename: @csvable.name }
|
73
|
+
# end
|
72
74
|
# end
|
73
|
-
# end
|
74
75
|
def self.add(key, &block)
|
75
76
|
define_method(_render_with_renderer_method_name(key), &block)
|
76
77
|
RENDERERS << key.to_sym
|
@@ -80,7 +81,7 @@ module ActionController
|
|
80
81
|
#
|
81
82
|
# To remove a csv renderer:
|
82
83
|
#
|
83
|
-
#
|
84
|
+
# ActionController::Renderers.remove(:csv)
|
84
85
|
def self.remove(key)
|
85
86
|
RENDERERS.delete(key.to_sym)
|
86
87
|
method_name = _render_with_renderer_method_name(key)
|
@@ -92,39 +93,39 @@ module ActionController
|
|
92
93
|
end
|
93
94
|
|
94
95
|
module ClassMethods
|
95
|
-
# Adds, by name, a renderer or renderers to the
|
96
|
-
#
|
96
|
+
# Adds, by name, a renderer or renderers to the `_renderers` available to call
|
97
|
+
# within controller actions.
|
97
98
|
#
|
98
99
|
# It is useful when rendering from an ActionController::Metal controller or
|
99
100
|
# otherwise to add an available renderer proc to a specific controller.
|
100
101
|
#
|
101
|
-
# Both ActionController::Base and ActionController::API
|
102
|
-
#
|
103
|
-
#
|
102
|
+
# Both ActionController::Base and ActionController::API include
|
103
|
+
# ActionController::Renderers::All, making all renderers available in the
|
104
|
+
# controller. See Renderers::RENDERERS and Renderers.add.
|
104
105
|
#
|
105
|
-
# Since ActionController::Metal controllers cannot render, the controller
|
106
|
-
#
|
107
|
-
#
|
106
|
+
# Since ActionController::Metal controllers cannot render, the controller must
|
107
|
+
# include AbstractController::Rendering, ActionController::Rendering, and
|
108
|
+
# ActionController::Renderers, and have at least one renderer.
|
108
109
|
#
|
109
|
-
# Rather than including ActionController::Renderers::All and including all
|
110
|
-
# you may specify which renderers to include by passing the renderer
|
111
|
-
#
|
112
|
-
# (
|
110
|
+
# Rather than including ActionController::Renderers::All and including all
|
111
|
+
# renderers, you may specify which renderers to include by passing the renderer
|
112
|
+
# name or names to `use_renderers`. For example, a controller that includes only
|
113
|
+
# the `:json` renderer (`_render_with_renderer_json`) might look like:
|
113
114
|
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
115
|
+
# class MetalRenderingController < ActionController::Metal
|
116
|
+
# include AbstractController::Rendering
|
117
|
+
# include ActionController::Rendering
|
118
|
+
# include ActionController::Renderers
|
118
119
|
#
|
119
|
-
#
|
120
|
+
# use_renderers :json
|
120
121
|
#
|
121
|
-
#
|
122
|
-
#
|
122
|
+
# def show
|
123
|
+
# render json: record
|
124
|
+
# end
|
123
125
|
# end
|
124
|
-
# end
|
125
126
|
#
|
126
|
-
# You must specify a
|
127
|
-
#
|
127
|
+
# You must specify a `use_renderer`, else the `controller.renderer` and
|
128
|
+
# `controller._renderers` will be `nil`, and the action will fail.
|
128
129
|
def use_renderers(*args)
|
129
130
|
renderers = _renderers + args
|
130
131
|
self._renderers = renderers.freeze
|
@@ -132,11 +133,11 @@ module ActionController
|
|
132
133
|
alias use_renderer use_renderers
|
133
134
|
end
|
134
135
|
|
135
|
-
# Called by
|
136
|
-
#
|
136
|
+
# Called by `render` in AbstractController::Rendering which sets the return
|
137
|
+
# value as the `response_body`.
|
137
138
|
#
|
138
|
-
# If no renderer is found,
|
139
|
-
#
|
139
|
+
# If no renderer is found, `super` returns control to
|
140
|
+
# `ActionView::Rendering.render_to_body`, if present.
|
140
141
|
def render_to_body(options)
|
141
142
|
_render_to_body_with_renderer(options) || super
|
142
143
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# :markup: markdown
|
4
|
+
|
3
5
|
module ActionController
|
4
6
|
module Rendering
|
5
7
|
extend ActiveSupport::Concern
|
@@ -10,8 +12,8 @@ module ActionController
|
|
10
12
|
# Documentation at ActionController::Renderer#render
|
11
13
|
delegate :render, to: :renderer
|
12
14
|
|
13
|
-
# Returns a renderer instance (inherited from ActionController::Renderer)
|
14
|
-
#
|
15
|
+
# Returns a renderer instance (inherited from ActionController::Renderer) for
|
16
|
+
# the controller.
|
15
17
|
attr_reader :renderer
|
16
18
|
|
17
19
|
def setup_renderer! # :nodoc:
|
@@ -24,113 +26,139 @@ module ActionController
|
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
|
-
# Renders a template and assigns the result to
|
29
|
+
# Renders a template and assigns the result to `self.response_body`.
|
30
|
+
#
|
31
|
+
# If no rendering mode option is specified, the template will be derived from
|
32
|
+
# the first argument.
|
33
|
+
#
|
34
|
+
# render "posts/show"
|
35
|
+
# # => renders app/views/posts/show.html.erb
|
36
|
+
#
|
37
|
+
# # In a PostsController action...
|
38
|
+
# render :show
|
39
|
+
# # => renders app/views/posts/show.html.erb
|
40
|
+
#
|
41
|
+
# If the first argument responds to `render_in`, the template will be rendered
|
42
|
+
# by calling `render_in` with the current view context.
|
43
|
+
#
|
44
|
+
# class Greeting
|
45
|
+
# def render_in(view_context)
|
46
|
+
# view_context.render html: "<h1>Hello, World</h1>"
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# def format
|
50
|
+
# :html
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# render(Greeting.new)
|
55
|
+
# # => "<h1>Hello, World</h1>"
|
28
56
|
#
|
29
|
-
#
|
30
|
-
#
|
57
|
+
# render(renderable: Greeting.new)
|
58
|
+
# # => "<h1>Hello, World</h1>"
|
31
59
|
#
|
32
|
-
#
|
33
|
-
# # => renders app/views/posts/show.html.erb
|
60
|
+
# #### Rendering Mode
|
34
61
|
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# # => renders app/views/posts/show.html.erb
|
62
|
+
# `:partial`
|
63
|
+
# : See ActionView::PartialRenderer for details.
|
38
64
|
#
|
39
|
-
#
|
40
|
-
#
|
65
|
+
# render partial: "posts/form", locals: { post: Post.new }
|
66
|
+
# # => renders app/views/posts/_form.html.erb
|
41
67
|
#
|
42
|
-
#
|
68
|
+
# `:file`
|
69
|
+
# : Renders the contents of a file. This option should **not** be used with
|
70
|
+
# unsanitized user input.
|
43
71
|
#
|
44
|
-
#
|
45
|
-
#
|
72
|
+
# render file: "/path/to/some/file"
|
73
|
+
# # => renders /path/to/some/file
|
46
74
|
#
|
47
|
-
#
|
48
|
-
#
|
75
|
+
# `:inline`
|
76
|
+
# : Renders an ERB template string.
|
49
77
|
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
78
|
+
# @name = "World"
|
79
|
+
# render inline: "<h1>Hello, <%= @name %>!</h1>"
|
80
|
+
# # => renders "<h1>Hello, World!</h1>"
|
53
81
|
#
|
54
|
-
#
|
55
|
-
#
|
82
|
+
# `:body`
|
83
|
+
# : Renders the provided text, and sets the content type as `text/plain`.
|
56
84
|
#
|
57
|
-
#
|
58
|
-
#
|
85
|
+
# render body: "Hello, World!"
|
86
|
+
# # => renders "Hello, World!"
|
59
87
|
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
# # => renders "<h1>Hello, World!</h1>"
|
88
|
+
# `:plain`
|
89
|
+
# : Renders the provided text, and sets the content type as `text/plain`.
|
63
90
|
#
|
64
|
-
#
|
65
|
-
#
|
91
|
+
# render plain: "Hello, World!"
|
92
|
+
# # => renders "Hello, World!"
|
66
93
|
#
|
67
|
-
#
|
68
|
-
#
|
94
|
+
# `:html`
|
95
|
+
# : Renders the provided HTML string, and sets the content type as
|
96
|
+
# `text/html`. If the string is not `html_safe?`, performs HTML escaping on
|
97
|
+
# the string before rendering.
|
69
98
|
#
|
70
|
-
#
|
71
|
-
#
|
99
|
+
# render html: "<h1>Hello, World!</h1>".html_safe
|
100
|
+
# # => renders "<h1>Hello, World!</h1>"
|
72
101
|
#
|
73
|
-
#
|
74
|
-
#
|
102
|
+
# render html: "<h1>Hello, World!</h1>"
|
103
|
+
# # => renders "<h1>Hello, World!</h1>"
|
75
104
|
#
|
76
|
-
#
|
77
|
-
# Renders the provided
|
78
|
-
#
|
79
|
-
#
|
105
|
+
# `:json`
|
106
|
+
# : Renders the provided object as JSON, and sets the content type as
|
107
|
+
# `application/json`. If the object is not a string, it will be converted to
|
108
|
+
# JSON by calling `to_json`.
|
80
109
|
#
|
81
|
-
#
|
82
|
-
#
|
110
|
+
# render json: { hello: "world" }
|
111
|
+
# # => renders "{\"hello\":\"world\"}"
|
83
112
|
#
|
84
|
-
#
|
85
|
-
#
|
113
|
+
# `:renderable`
|
114
|
+
# : Renders the provided object by calling `render_in` with the current view
|
115
|
+
# context. The response format is determined by calling `format` on the
|
116
|
+
# renderable if it responds to `format`, falling back to `text/html` by
|
117
|
+
# default.
|
86
118
|
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
# +application/json+. If the object is not a string, it will be converted
|
90
|
-
# to JSON by calling +to_json+.
|
119
|
+
# render renderable: Greeting.new
|
120
|
+
# # => renders "<h1>Hello, World</h1>"
|
91
121
|
#
|
92
|
-
# render json: { hello: "world" }
|
93
|
-
# # => renders "{\"hello\":\"world\"}"
|
94
122
|
#
|
95
123
|
# By default, when a rendering mode is specified, no layout template is
|
96
124
|
# rendered.
|
97
125
|
#
|
98
|
-
#
|
126
|
+
# #### Options
|
99
127
|
#
|
100
|
-
#
|
101
|
-
# Hash of instance variable assignments for the template.
|
128
|
+
# `:assigns`
|
129
|
+
# : Hash of instance variable assignments for the template.
|
102
130
|
#
|
103
|
-
#
|
104
|
-
#
|
131
|
+
# render inline: "<h1>Hello, <%= @name %>!</h1>", assigns: { name: "World" }
|
132
|
+
# # => renders "<h1>Hello, World!</h1>"
|
105
133
|
#
|
106
|
-
#
|
107
|
-
# Hash of local variable assignments for the template.
|
134
|
+
# `:locals`
|
135
|
+
# : Hash of local variable assignments for the template.
|
108
136
|
#
|
109
|
-
#
|
110
|
-
#
|
137
|
+
# render inline: "<h1>Hello, <%= name %>!</h1>", locals: { name: "World" }
|
138
|
+
# # => renders "<h1>Hello, World!</h1>"
|
111
139
|
#
|
112
|
-
#
|
113
|
-
# The layout template to render. Can also be
|
114
|
-
#
|
140
|
+
# `:layout`
|
141
|
+
# : The layout template to render. Can also be `false` or `true` to disable or
|
142
|
+
# (re)enable the default layout template.
|
115
143
|
#
|
116
|
-
#
|
117
|
-
#
|
144
|
+
# render "posts/show", layout: "holiday"
|
145
|
+
# # => renders app/views/posts/show.html.erb with the app/views/layouts/holiday.html.erb layout
|
118
146
|
#
|
119
|
-
#
|
120
|
-
#
|
147
|
+
# render "posts/show", layout: false
|
148
|
+
# # => renders app/views/posts/show.html.erb with no layout
|
121
149
|
#
|
122
|
-
#
|
123
|
-
#
|
150
|
+
# render inline: "<h1>Hello, World!</h1>", layout: true
|
151
|
+
# # => renders "<h1>Hello, World!</h1>" with the default layout
|
124
152
|
#
|
125
|
-
#
|
126
|
-
# The HTTP status code to send with the response. Can be specified as a
|
127
|
-
#
|
153
|
+
# `:status`
|
154
|
+
# : The HTTP status code to send with the response. Can be specified as a
|
155
|
+
# number or as the status name in Symbol form. Defaults to 200.
|
128
156
|
#
|
129
|
-
#
|
130
|
-
#
|
157
|
+
# render "posts/new", status: 422
|
158
|
+
# # => renders app/views/posts/new.html.erb with HTTP status code 422
|
131
159
|
#
|
132
|
-
#
|
133
|
-
#
|
160
|
+
# render "posts/new", status: :unprocessable_entity
|
161
|
+
# # => renders app/views/posts/new.html.erb with HTTP status code 422
|
134
162
|
#
|
135
163
|
#--
|
136
164
|
# Check for double render errors and set the content_type after rendering.
|
@@ -140,7 +168,7 @@ module ActionController
|
|
140
168
|
end
|
141
169
|
|
142
170
|
# Similar to #render, but only returns the rendered template as a string,
|
143
|
-
# instead of setting
|
171
|
+
# instead of setting `self.response_body`.
|
144
172
|
#--
|
145
173
|
# Override render_to_string because body can now be set to a Rack body.
|
146
174
|
def render_to_string(*)
|