1

我刚开始玩haml,我试图了解我做错了什么。

文章/edit.html.haml

=render partial: 'form', f: f
  .submit_field
    =f.submit "Update Article"

文章/_form.html.haml

=form_for @article do |f|
  -if @article.errors.any?
  #error_explanation
    %h2
      =pluralize(@article.errors.count, "error")
      prohibited this task from being saved:
      %ul
        -@article.errors.full_messages.each do |msg|
          %li=msg

  .text_field
    =f.label :title 
    %br
    =f.text_field :title

  .text_field
    =f.label :body
    %br
    =f.text_area :body, {rows: 10, cols: 40}

我收到此错误:语法错误,意外的keyword_ensure,期望 $end at .submit_field 。谁能指出我正确的方向?

4

1 回答 1

1

尝试将提交按钮移到您的表单部分中:

文章/edit.html.haml

=form_for @article do |f|
  =render partial: 'form', f: f

文章/_form.html.haml

-if @article.errors.any?
#error_explanation
  %h2
    =pluralize(@article.errors.count, "error")
    prohibited this task from being saved:
    %ul
      -@article.errors.full_messages.each do |msg|
        %li=msg

.text_field
  =f.label :title 
  %br
  =f.text_field :title

.text_field
  =f.label :body
  %br
  =f.text_area :body, {rows: 10, cols: 40}

.submit_field
  =f.submit "Update Article"
于 2012-09-03T02:19:57.717 回答