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"
答案 0 :(得分:2)
错误是由行
引起的= @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
答案 1 :(得分:1)
- 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"