【发布时间】:2013-06-23 20:01:35
【问题描述】:
我试图在我的一个 Haml 视图中将一些(未渲染的)cmets 放入 If/Else 语句中,但这似乎会导致问题。
我想要以下代码:
- # Stuff like ______ activates the if statement
- if @condition
(Some code)
- # Stuff like _____ activates the else statement
- else
(Some other code)
不幸的是,Rails 向我抛出了这个错误:
Got "else" with no preceding "if"
如果我删除“else”评论,即
- # Stuff like ______ activates the if statement
- if @condition
(Some code)
- else
(Some other code)
一切都按预期进行。问题不在于评论本身。我必须删除实际的 Ruby 代码行(包括连字符)才能使其呈现。也就是说,即使我只是在一个连字符前面留下一个空行,就像这样:
- # Stuff like ______ activates the if statement
- if @condition
(Some code)
-
- else
(Some other code)
我得到同样的错误。其他可能相关的细节:稍后有更多代码与 if/else 语句处于相同的缩进级别(不在其中),并且整个内容嵌套在表单中。有人可以向我解释发生了什么问题吗?非常感谢!
附:这是我的第一个 SO 问题,所以如果我提出不当,请告诉我。
【问题讨论】:
-
如果您尝试在 else 之前更深地缩进评论会发生什么?
标签: ruby-on-rails ruby haml