Slim "Failure/Error: render ActionView::Template::Error: Unexpected end of file"

I was getting an error from Slim template saying:

Failure/Error: render
ActionView::Template::Error:
  Unexpected end of file
    my_file.html.slim, Line 15

, where the file had only 15 lines

I searched for the error and found:

# https://github.com/stonean/slim/blob/master/lib/slim/parser.rb
def parse_broken_line
  broken_line = @line.strip
  while broken_line[-1] == ?\\
    next_line || syntax_error!('Unexpected end of file')
    broken_line << "\n" << @line.strip
  end
  broken_line
end

What this means is that I had an extra trailing slash on one of the lines in a Slim escape that indicates that there are multiple lines. Slim was expecting another line, but didn’t see it and instead saw the end of the file. Removing the extra trailing slash fixed the problem.

Categories: development

« How I Patched Devise to Force Login for Twitter and Facebook Making Recommendations with Apache Mahout Presentation »

Comments