我在 rails 项目的 ruby 中的 haml 文件中的错误

Errors in my haml file in a ruby on rails project

我正在按照教程制作论坛!当我在 index.html.haml

中编写此代码时
- @posts.each do |post|
  %h2= post.title
%p 
Published at
= time_ago_in_words(post.created_at)
= link_to "New Post", new_post_path

我遇到了这个错误:

app/views/posts/index.html.haml:7: syntax error, unexpected keyword_ensure, expecting keyword_end
app/views/posts/index.html.haml:10: syntax error, unexpected end-of-input, expecting keyword_end

我真的需要你的帮助!

我觉得可能是缩进问题。试试这个:

- @posts.each do |post|
  %h2= post.title
  %p 
    Published at
    = time_ago_in_words(post.created_at)
= link_to "New Post", new_post_path

确保您在方法的末尾键入了 "end",并在模型的最后一行输入了另一个 "end"。

没有看到你的代码,看起来你在某处遗漏了 "end" 语法。