我有一个带有 has_one 和多态关联的模型,如下所示:
class Disc < ActiveRecord::Base
has_one :item, :as => :article, :dependent => :destroy
accepts_nested_attributes_for :item
end
class Item < ActiveRecord::Base
belongs_to :article, :polymorphic => true
end
我正在尝试使用嵌套表单,但仅显示 disc 的字段,而不显示 item 的字段。这是我的表格:
<%= form_for(@disc) do |d| %>
<% d.fields_for :item do |f| %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :stock %><br />
<%= f.number_field :stock, :min => 0 %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<% end %>
DISC:
<div class="field">
<%= d.label :num_discs %><br />
<%= d.number_field :num_discs %>
</div>
<div class="field">
<%= d.label :audio %><br />
<%= d.text_field :audio %>
</div>
<div class="field">
<%= d.label :subtitles %><br />
<%= d.text_field :subtitles %>
</div>
<div class="actions">
<%= d.submit %>
</div>
<% end %>
控制台中未显示任何错误。