ruby on rails – Missing keyword_end on haml partial template processing – Education Career Blog

Because I was getting myself annoyed with the HTML tags, I started to convert my project to HAML, since it is a lot better structured. I am glad the installation provides the tool html2haml to help me with it.

While being syntactically correct, processing the file gives me a weird error I don’t quite get:

/stories/_story.html.haml:28: syntax error, unexpected keyword_ensure, expecting keyword_end
...:Util.html_safe(_erbout);ensure;@haml_buffer = @haml_buffer....
...                               ^
/stories/_story.html.haml:31: syntax error, unexpected $end, expecting keyword_end

My haml source only has 27 lines, and since I am very new to this, I have no idea where it is gone wrong… here is the code:

%h1= story.title
    by #{link_to, story.user}
#story-short= story.short_desc
- if logged_in? and == story.user_id
      = link_to 'Edit', edit_story_path(story)
      \#{link_to 'Delete', story, :method => 'delete', :confirm => 'Are you really sure?'}
  - story.body.split("\n").each do |line|
  - if line.strip.empty?
  - else
    %p= line.strip
  %p{:onclick => "$('#comments').find('dl').slideToggle();"} Comments to this story (click to expand)
    = render :partial => 'comment', :collection => @story.comments
    - if logged_in? and != story.user_id
      %dt Leave a comment:
        = form_for story, do |f|
          .field= f.text_area :body
          .actions= f.submit "Comment!"

So yeah, I’d really love to know where this is wrong. Checked it several times, maybe a bug?

Thanks for your time.


The lines beneath - story.body.split("\n").each do |line| aren’t indented. This means that Haml doesn’t know to automatically add an end for the block, which is causing the error in question.

Leave a Comment