【问题标题】:syntax error, unexpected keyword_ensure, expecting end-of-input in haml语法错误,意外的keyword_ensure,期望在haml中结束输入
【发布时间】:2015-11-17 02:40:42
【问题描述】:

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"

【问题讨论】:

    标签: ruby-on-rails haml


    【解决方案1】:

    错误是由线条引起的

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

    这些行中的第二行被解析为传递给方法的块,即使它不是。然后,Haml 会插入 end,这最终会导致您看到额外的 end 错误。

    修复缩进相同的行:

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

    或者你可以在这里使用interpolation

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 如果您确实需要该评论,您需要将其评论在与内容相同的级别。但这很多余。
      • 我已经复制了你的代码,但它再次给出了同样的错误,主要问题是 Rails 服务器在第 15 行给出错误,但代码只有 13 行。
      • 如果你指的是#errors,那不是评论,那是valid Haml。错误迷雾在其他地方。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多