class ActionView::Template::Handlers::ERB
def find_lineno_offset(compiled, source_lines, highlight, error_lineno)
Use the difference between the compiled and source sizes to
The compiled template is likely to be longer than the source.
chance of finding the correct line
Searches in reverse from the backtrace lineno so we have a better
Return the offset between the error lineno and the source lineno.
def find_lineno_offset(compiled, source_lines, highlight, error_lineno) first_index = error_lineno - 1 - compiled.size + source_lines.size first_index = 0 if first_index < 0 last_index = error_lineno - 1 last_index = source_lines.size - 1 if last_index >= source_lines.size last_index.downto(first_index) do |line_index| next unless source_lines[line_index].include?(highlight) return error_lineno - 1 - line_index end raise LocationParsingError, "Couldn't find code snippet" end