0
我试图做一个嵌套窗体, 我的窗体是有很多Bs的模型A,并且必须将它们全部保存在保存窗体上。 的问题是:我是一个控制器上建设3个BS,但只有一个字段被显示出来, 下面的代码:嵌套窗体has_many
A类:
class A < ActiveRecord::Base
has_many :bs
accepts_nested_attributes_for :bs
end
B类:
class B < ActiveRecord::Base
belongs_to :a
end
控制器:
class AController < ApplicationController
def new
@a = A.new
3.times { @a.bs.build }
end
end
A和B形成:
<%= form_for :a do |f| %>
<%= f.fields_for :bs do |b| %>
<%= b.text_field :name, :class => 'default' %>
<% end %>
<% end %>