我在我的Rails应用程序中有一个模型产品,它的属性可以编辑,我想让用户评论他所做的每一个更改(评论可以是空白的).所以,Product has_many:comments,它accept_nested_attributes_for:注释,如果注释为空,则拒绝它.
因此,Product的编辑表单是一种多模型形式.我遇到的问题是:
也许我错了,fields_for不适合这种情况?
基于Tots答案我只是简单一点(Rails 3兼容):
<%= f.fields_for :comments, @product.comments.build do |comment| %>
<%= comment.label :comments %><br />
<%= comment.text_area :content %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2844 次 |
| 最近记录: |