【问题标题】:form_for method using slimform_for 方法使用 slim
【发布时间】:2012-10-30 16:01:00
【问题描述】:

我查看了 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|

但我遇到了语法错误。

【问题讨论】:

    标签: ruby-on-rails slim-lang


    【解决方案1】:

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

    = 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
    

    【讨论】:

      【解决方案2】:

      马里奥写道:

      = form_for([@post, @post.cmets.build]) 做 |f| div.field = f.label:评论者 br = f.text_field:评论者 div.field = f.label :body br = f.text_area:正文 div.actions = f.提交

      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多