每次我运行此代码我都会收到错误,无法找到我做错了什么,它说了一些关于synatic error的标识,期待关键字_do或' {'或者'('。任何人都对它可能是什么有任何建议?
_form.html.haml
= simple_form_for @pin, html: { multipart: true } do |f|
= if @pin.errors.any?
#errors
%h2
= pluralize(@pin.errors.count, "error")
prevented this pin from saving
%ul
- @pin.errors.full_messages.each do |msg|
%li = msg
.form-group
= f.input :title, input_html: { class: 'form-control' }
.form-group
= f.input :description, input_html: { class: 'form-control' }
= f.button :submit, class: "btn btn-primary"
答案 0 :(得分:1)
正如评论中指出的那样,HAML必须基于缩进进行格式化。因此,如果你有一个if语句,那么你的下一行应该从if缩进2步,而div或任何其他html元素的内容将从其父级缩进2行。您的代码看起来应该更像:
= simple_form_for @pin, html: { multipart: true } do |f|
= if @pin.errors.any?
#errors
%h2
= pluralize(@pin.errors.count, "error")
prevented this pin from saving
%ul
- @pin.errors.full_messages.each do |msg|
%li = msg
.form-group
= f.input :move_in, input_html: { class: 'form-control' }
.form-group
= f.input :move_out, input_html: { class: 'form-control' }
= f.button :submit, class: "btn btn-primary"