我正在處理一個項目,該項目需要嵌套窗體將多個閥門添加到單個訂單(在這種情況下訂單被稱爲rfq)。Rails cocoon f.fields_for not working
我得到這個錯誤:
ActionView::Template::Error (uninitialized constant Rfq::Valf):
48: </div>
49:
50: <div id="valves">
51: <%= f.fields_for :valves do |valve| %>
52: <%= render 'valve_fields', f: valve %>
53: <% end %>
54: <%= link_to_add_association 'add valve', f, :valves %>
這裏的形式部分的相關部分,
<%= form_for @rfq do |f| %>
...
<div class="field">
<%= f.label :application %><br>
<%= f.text_field :application %>
</div>
<div id="valves">
<%= f.fields_for :valves do |valve| %>
<%= render 'valve_fields', f: valve %>
<% end %>
<%= link_to_add_association 'add valve', f, :valves %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
閥門領域部分:
<div class="nested-fields">
<div class="field">
<%= f.label :line %>
<%= f.text_field :productline %>
</div>
<%= link_to_remove_association "remove valve", f %>
</div>
詢價型號:
class Rfq < ActiveRecord::Base
has_many :valves
accepts_nested_attributes_for :valves, :allow_destroy => true
belongs_to :customer
has_paper_trail
end
閥門型號:
class Valve < ActiveRecord::Base
belongs_to :rfq
has_paper_trail
end
在此先感謝
請發佈您的_valve_fields.html.erb文件。 – jljohnstone
@jljohnstone添加了部分字段。 – Suavocado
我在這裏沒有看到任何明顯錯誤的東西。如果可以,請發佈RFQ和Valve型號。 – jljohnstone