Haml Rails部分和当地人问题

时间:2021-04-23 16:48:22

I just started playing around with haml and I am trying to understand what I am doing wrong.

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

articles/edit.html.haml

文章/ edit.html.haml

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

articles/_form.html.haml

文章/ _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}

I get this error: syntax error, unexpected keyword_ensure, expecting $end at .submit_field . Can anybody point me in the right direction?

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

1 个解决方案

#1


1  

Try moving the submit button in to your form partial:

尝试将提交按钮移动到表单部分:

articles/edit.html.haml

文章/ edit.html.haml

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

articles/_form.html.haml

文章/ _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"

#1


1  

Try moving the submit button in to your form partial:

尝试将提交按钮移动到表单部分:

articles/edit.html.haml

文章/ edit.html.haml

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

articles/_form.html.haml

文章/ _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"