【问题标题】:Errors in my haml file in a ruby on rails projectruby on rails 项目中我的haml文件中的错误
【发布时间】:2015-11-29 01:24:13
【问题描述】:

我正在学习制作论坛的教程!当我在 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:语法错误,意外的keyword_ensure,期待keyword_end
app/views/posts/index.html.haml:10:语法错误,意外的输入结束,期待关键字_end

我真的需要你的帮助!

【问题讨论】:

  • 你知道 HAML 是基于缩进的,对吧?

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 haml html2haml


【解决方案1】:

我认为这可能是一个缩进问题。试试这个:

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

【讨论】:

    【解决方案2】:

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

    没有看到您的代码,您似乎在某处缺少“结束”语法。

    【讨论】:

    • HAML 不需要“end”关键字。它通过缩进处理范围。
    • 不,我的代码没有任何错误,我找到了解决方案。谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多