14

我查看了 slim 的文档,但仍然无法弄清楚如何在 slim 中执行此操作:

<%= form_for([@post, @post.comments.build]) do |f| %>
  <div class="field">
    <%= f.label :commenter %><br />
    <%= f.text_field :commenter %>
  </div>
  <div class="field">
    <%= f.label :body %><br />
    <%= f.text_area :body %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

我试着像这样翻译第一行

= form_for([@post, @post.reviews.build]) do |f|

但我收到语法错误。

4

2 回答 2

27

之前遇到过类似的问题,我认为您只需要一些子元素!尝试这个:

= form_for([@post, @post.comments.build]) do |f|
  div.field
    = f.label :commenter
    br
    = f.text_field :commenter
  div.field
    = f.label :body
    br
    = f.text_area :body
  div.actions
    = f.submit
于 2012-11-02T09:08:19.070 回答
0

马里奥写道:

= form_for([@post, @post.comments.build]) 做 |f| div.field = f.label :commenter br = f.text_field :commenter div.field = f.label :body br = f.text_area :body div.actions = f.submit

div 不是必需的。所以我会这样做:

= form_for([@post, @post.comments.build]) do |f|
  .field
    = f.label :commenter
    br
    = f.text_field :commenter
  .field
    = f.label :body
    br
    = f.text_area :body
  .actions
    = f.submit
于 2019-11-28T00:03:55.637 回答