mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Render objects that respond_to render_in in controllers
In https://github.com/rails/rails/pull/36388, we supported passing objects that `respond_to` `render_in` to `render`, but _only_ in views. This change does the same for controllers, as Rails generally gives the expectation that `render` behaves the same in both contexts. Co-authored-by: Aaron Patterson <tenderlove@github.com>
This commit is contained in:
parent
4fbb1e9f5b
commit
20a83f52d7
3 changed files with 9 additions and 3 deletions
|
@ -10,9 +10,6 @@ class TestComponent < ActionView::Base
|
|||
@title = title
|
||||
end
|
||||
|
||||
# Entrypoint for rendering. Called by ActionView::RenderingHelper#render.
|
||||
#
|
||||
# Returns ActionView::OutputBuffer.
|
||||
def render_in(view_context)
|
||||
self.class.compile
|
||||
@view_context = view_context
|
||||
|
@ -20,6 +17,10 @@ class TestComponent < ActionView::Base
|
|||
rendered_template
|
||||
end
|
||||
|
||||
def format
|
||||
:html
|
||||
end
|
||||
|
||||
def self.template
|
||||
<<~'erb'
|
||||
<span title="<%= title %>">(<%= render(plain: "Inline render") %>)</span>
|
||||
|
|
|
@ -25,6 +25,9 @@ module ActionView
|
|||
def render_to_object(context, options) # :nodoc:
|
||||
if options.key?(:partial)
|
||||
render_partial_to_object(context, options)
|
||||
elsif options.key?(:object)
|
||||
object = options[:object]
|
||||
AbstractRenderer::RenderedTemplate.new(object.render_in(context), object)
|
||||
else
|
||||
render_template_to_object(context, options)
|
||||
end
|
||||
|
|
|
@ -144,6 +144,8 @@ module ActionView
|
|||
else
|
||||
if action.respond_to?(:permitted?) && action.permitted?
|
||||
options = action
|
||||
elsif action.respond_to?(:render_in)
|
||||
options[:object] = action
|
||||
else
|
||||
options[:partial] = action
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue