form_for method using slim

14,155

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
Share:
14,155

Related videos on Youtube

AlexBrand
Author by

AlexBrand

Updated on September 16, 2022

Comments

  • AlexBrand
    AlexBrand almost 2 years

    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.