Skip to content

Commit 6afabbf

Browse files
committed
better solution outside of template compilation
1 parent caf707a commit 6afabbf

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

lib/view_component/base.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ def render_in(view_context, &block)
141141
value = nil
142142

143143
@output_buffer.with_buffer do
144+
@view_context.instance_variable_set(:@virtual_path, virtual_path)
145+
144146
rendered_template = render_template_for(@__vc_requested_details).to_s
145147

146148
# Avoid allocating new string when output_preamble and output_postamble are blank

lib/view_component/template.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ def compile_to_component
9898
@component.silence_redefinition_of_method(call_method_name)
9999

100100
# rubocop:disable Style/EvalWithLocation
101-
@component.class_eval <<~RUBY, @path, @lineno - 1
101+
@component.class_eval <<~RUBY, @path, @lineno
102102
def #{call_method_name}
103-
@view_context.instance_variable_set(:@virtual_path, virtual_path)
104103
#{compiled_source}
105104
end
106105
RUBY

0 commit comments

Comments
 (0)