Haml Rails部分和当地人问题

时间:2012-09-03 01:50:48

标签: ruby-on-rails haml partial-views local-variables renderpartial

我刚刚开始玩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}

我在.submit_field收到此错误:语法错误,意外的keyword_ensure,期待$ end 。任何人都可以指出我正确的方向吗?

1 个答案:

答案 0 :(得分: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"