diff --git a/activesupport/lib/active_support/syntax_error_proxy.rb b/activesupport/lib/active_support/syntax_error_proxy.rb index 59d96d86813b..1e72a191b5a3 100644 --- a/activesupport/lib/active_support/syntax_error_proxy.rb +++ b/activesupport/lib/active_support/syntax_error_proxy.rb @@ -43,7 +43,8 @@ def backtrace_locations private def parse_message_for_trace - if __getobj__.to_s.start_with?("(eval") + # If RUBY_VERSION < 3.2, the path method is not available for SyntaxError + if __getobj__.try(:path).try(:start_with?,"(eval") || __getobj__.to_s.start_with?("(eval") # If the exception is coming from a call to eval, we need to keep # the path of the file in which eval was called to ensure we can # return the right source fragment to show the location of the