Rails将fields_for
(嵌套属性)生成的表单输入与<div class="fields">...</div>
包装在一起。我需要将课程改为&#34; col-md-4&#34;或者至少添加它。我该怎么做?
<%= form.fields_for :products_colors do |pc| %>
<%= render 'products_color', :pc => pc %>
<% end %>
答案 0 :(得分:4)
文档:
http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-fields_for
fields_for(record_name, record_object = nil, options = {}, &block)
您可以将class
添加到options
,如下所示:
fields_for(:products_color, nil, { :class => 'col-md-4' }) do ...
答案 1 :(得分:0)
对我来说,添加包装器::false可以解决问题。
form.fields_for(association, new_object, child_index: 'new_record', :wrapper => false )