ruby haml意外结束错误

时间:2017-02-13 20:43:09

标签: ruby

enter image description here

_form代码是:

    = simple_form_for @book, html: { multipart: true } do |f|
-  if @book.errors.any?
 #errors
 %p
 = @book.errors.count
 Prevented this book from saving

 %ul
 - @book.errors.full_message.each do |msg|
 %li= msg

 .panel-body
 =f.input :title, input_html: {class: 'form-control'}
 =f.input :description, input_html: {class: 'form-control'}

 =f.button :submit, class: "btn btn-primary"

1 个答案:

答案 0 :(得分:2)

HAML嵌套由空格决定。您需要插入一些,以便HAML解释器知道嵌套的范围。例如,form中的所有内容都必须显示比form行更多的前一个空格

    = simple_form_for @book, html: { multipart: true } do |f|
      - if @book.errors.any?
        #errors
        %p
        = @book.errors.count
        Prevented this book from saving

        %ul
        - @book.errors.full_message.each do |msg|
          %li= msg

     .panel-body
       =f.input :title, input_html: {class: 'form-control'}
       =f.input :description, input_html: {class: 'form-control'}

       =f.button :submit, class: "btn btn-primary"