0

我的观点是

<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在视图中。请帮助我哪里错了并纠正他们

4

1 回答 1

0

代替

<% f.fields_for :item_companies do |c| %>

经过

<%= f.fields_for :item_companies do |c| %>
于 2013-03-31T13:43:48.233 回答