Rails 茧 f.fields_for 不工作
Rails cocoon f.fields_for not working
我正在处理一个需要嵌套表单以将多个阀门添加到单个订单的项目(在这种情况下订单称为 rfq)。
我收到这个错误:
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" class 名称,如下图所示。
class Rfq < ActiveRecord::Base
has_many :valves, :class_name => "Valve"
accepts_nested_attributes_for :valves, :allow_destroy => true
belongs_to :customer
has_paper_trail
end
我正在处理一个需要嵌套表单以将多个阀门添加到单个订单的项目(在这种情况下订单称为 rfq)。
我收到这个错误:
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" class 名称,如下图所示。
class Rfq < ActiveRecord::Base
has_many :valves, :class_name => "Valve"
accepts_nested_attributes_for :valves, :allow_destroy => true
belongs_to :customer
has_paper_trail
end