我的观点是
<h3> Register New Items </h3>
<div class="row">
<div class="span2 offset4">
<%= nested_form_for @item_categories, :url => items_path, :method => :post, :html => { :class => "item_category"} do |f| %>
<div><%= f.label :item_name %>
<%= f.text_field :item_name %></div>
</br>
<% f.fields_for :item_companies do |c| %>
<%= c.text_field :company_name %></div>
<%end%>
<div><%= f.submit "Submit" %></div>
<% end %>
</div>
控制器
@item_categories = ItemCategory.new
3.times do
item_company = @item_categories.item_companies.build
4.times { item_company.item_weights.build }
end
和模型是:
class ItemCategory < ActiveRecord::Base
attr_accessible :item_name
has_many :item_weights
has_many :item_companies#, :through=> :item_weights
accepts_nested_attributes_for :item_companies
end
class ItemCompany < ActiveRecord::Base
attr_accessible :company_name, :item_category_id
has_many :item_weights
has_many :item_categories#, :through=> :item_weights
end
class ItemWeight < ActiveRecord::Base
attr_accessible :item_category_id, :item_company_id, :weight
belongs_to :item_company
belongs_to :item_category
end
但我的观点并未显示c.text_field :company_name
。
请帮助我,我错了,并纠正他们
答案 0 :(得分:0)
替换
<% f.fields_for :item_companies do |c| %>
通过
<%= f.fields_for :item_companies do |c| %>