@@ -108,7 +108,7 @@ def render_in(view_context, &block)
108108 self . class . __vc_compile ( raise_errors : true )
109109
110110 @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 )
112112 self . __vc_original_view_context ||= view_context
113113
114114 @output_buffer = view_context . output_buffer
@@ -166,7 +166,7 @@ def render_in(view_context, &block)
166166 ""
167167 end
168168 ensure
169- view_context . instance_variable_set ( :@virtual_path , old_virtual_path )
169+ view_context . instance_variable_set ( :@virtual_path , @ old_virtual_path)
170170 @current_template = old_current_template
171171 end
172172
@@ -341,7 +341,9 @@ def content
341341
342342 @__vc_content =
343343 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
345347 elsif __vc_content_set_by_with_content_defined?
346348 @__vc_content_set_by_with_content
347349 end
@@ -358,6 +360,14 @@ def format
358360 self . class . __vc_response_format
359361 end
360362
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+
361371 private
362372
363373 attr_reader :view_context
0 commit comments