2012-10-30 42 views
14

我看過的苗條的文檔,我仍然無法弄清楚如何做到這一點的纖薄:的form_for方法,使用超薄

<%= 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| 

但我得到一個語法錯誤。

回答

26

之前遇到類似問題,我想你只需要一些子元素!試試這個:

= 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