簡體   English   中英

語法錯誤,意外的keyword_ensure,期望以haml結尾的輸入

[英]syntax error, unexpected keyword_ensure, expecting end-of-input in haml

Rails服務器出現以下錯誤,

語法錯誤,意外的keyword_ensure,預期輸入結束

= simple_form_for @recipe, html: { multipart: true } do |f|
  - if @recipe.errors.any?
    #errors
      %p
        = @recipe.errors.count
          Prevented this recipe from saving
      %ul
        - @recipe.errors.full_messages.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"

錯誤是由線條引起的

= @recipe.errors.count
  Prevented this recipe from saving

這些行中的第二行被解析為一個塊,即使沒有傳遞給該方法。 Haml然后插入end ,這最終會導致您看到額外的end錯誤。

要修復,只需縮進相同的行:

= @recipe.errors.count
Prevented this recipe from saving

或者,您可以在此處使用插值

#{@recipe.errors.count} Prevented this recipe from saving

之后的行- if @recipe.errors.any? 需要縮進一步。

= simple_form_for @recipe, html: { multipart: true } do |f|
  - if @recipe.errors.any?
    %p
      = @recipe.errors.count
        Prevented this recipe from saving
    %ul
      - @recipe.errors.full_messages.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"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM