@@ -108,7 +108,7 @@ def render_in(view_context, &block)
108
108
self . class . __vc_compile ( raise_errors : true )
109
109
110
110
@view_context = view_context
111
- old_virtual_path = view_context . instance_variable_get ( :@virtual_path )
111
+ @ old_virtual_path = view_context . instance_variable_get ( :@virtual_path )
112
112
self . __vc_original_view_context ||= view_context
113
113
114
114
@output_buffer = view_context . output_buffer
@@ -166,7 +166,7 @@ def render_in(view_context, &block)
166
166
""
167
167
end
168
168
ensure
169
- view_context . instance_variable_set ( :@virtual_path , old_virtual_path )
169
+ view_context . instance_variable_set ( :@virtual_path , @ old_virtual_path)
170
170
@current_template = old_current_template
171
171
end
172
172
@@ -341,7 +341,9 @@ def content
341
341
342
342
@__vc_content =
343
343
if __vc_render_in_block_provided?
344
- view_context . capture ( self , &@__vc_render_in_block )
344
+ with_original_virtual_path do
345
+ view_context . capture ( self , &@__vc_render_in_block )
346
+ end
345
347
elsif __vc_content_set_by_with_content_defined?
346
348
@__vc_content_set_by_with_content
347
349
end
@@ -358,6 +360,14 @@ def format
358
360
self . class . __vc_response_format
359
361
end
360
362
363
+ # @private
364
+ def with_original_virtual_path
365
+ @view_context . instance_variable_set ( :@virtual_path , @old_virtual_path )
366
+ yield
367
+ ensure
368
+ @view_context . instance_variable_set ( :@virtual_path , virtual_path )
369
+ end
370
+
361
371
private
362
372
363
373
attr_reader :view_context
0 commit comments