chandradot99
chandradot99

Reputation: 3866

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

rails server is following error,

syntax error, unexpected keyword_ensure, expecting end-of-input

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

Upvotes: 0

Views: 608

Answers (2)

matt
matt

Reputation: 79723

The error is caused by the lines

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

The second of these lines is being parsed as a block being passed to the method even though it isn’t. Haml is then inserting the end, which ultimately causes the extra end error you see.

To fix just indent the lines the same:

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

Or perhaps you could use interpolation here:

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

Upvotes: 2

max
max

Reputation: 101891

The line after - if @recipe.errors.any? needs to be indented one step.

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

Upvotes: 1

Related Questions