我有两个模型:
class PortStock < ApplicationRecord
has_many :closed_positions
accepts_nested_attributes_for :closed_positions
end
class ClosedPosition < ApplicationRecord
belongs_to :closer, class_name: "PortStock", foreign_key: "closer_id"
belongs_to :closed, class_name: "PortStock", foreign_key: "port_stock_id"
end
我知道这种联系是有效的,因为我已经测试过了。
我有一份表格
views/port_stocks/sell/_form.html.erb
看起来是这样的:
<%= simple_form_for @port_stock, url: port_stocks_sell_order_path, method: :post do |f| %>
<% @port_stocks.each do |port_stock| %>
<%= f.simple_fields_for :closed_positions, html: { class: "form-inline" } do |c| %>
<%= c.input_field :num_units, id: "sell-ps-#{port_stock.id}", class: "form-control mx-sm-3" %>
<% end %>
<% end %>
<%= f.button :submit, "Sell Stock", class:"btn btn-primary" %>
<% end %>
但是,当HTML被呈现时,它不会呈现
simple_fields_for
.
如果我把
binding.pry
就在
f.simple_fields_for
线,它停止执行。如果我把它放在后面,它不会。这说明
简单字段
不会被处决。
但每
the docs
我应该这样做。
我错过了什么?为什么不在
简单字段
?