form_for method using slim
Asked Answered
I

2

14

I have looked at the documentation of slim, and I still can't figure out how to do this in 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 %>

I try to translate the first line like this

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

But I am getting a syntax error.

Impiety answered 30/10, 2012 at 16:1 Comment(0)
M
27

Was experiencing a similar issue earlier, I think you just need some child elements! Try this:

= 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
Myke answered 2/11, 2012 at 9:8 Comment(0)
R
0

Mario wrote:

= 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

Div is not necessary . So I would do :

= 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
Roulette answered 28/11, 2019 at 0:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.