2016-04-24 49 views
-5

每次我運行這段代碼我得到一個錯誤找不到我做了什麼錯誤它說什麼關於synatic錯誤tidentifier,期待keyword_do或'{'或'('。任何人有任何建議它可能是什麼?ruby​​ on rails標識符error 1


_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

[從HAML文件:(http://haml.info/docs/yardoc/)Haml的使用__indentation__帶來的單個元素來表示HTML結構。 –

+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" 
+0

哦,好的,謝謝你,現在我明白了@trh –