工作時,我認爲我嘗試建立一個嵌套形式嵌套形式不是的has_many
<%= semantic_form_for @order do |f| %>
<%= f.inputs :name => "Detail", :for => :order_detail do |od| %>
<%= od.input :shoe_id, :collection => Shoe.all.map{|s|[s.article_number,s.id]} %>
<%= od.input :size_id, :collection => Size.all.map{|s|[s.number,s.id]} %>
<%= od.input :color_id, :collection => Color.all.map{|c|[c.name,c.id]} %>
<%= od.input :quantity %>
<%- end -%>
<%- end -%>
它的工作原理我已經有了一個模型訂單
class Order < ActiveRecord::Base
has_many :order_details, :class_name => "OrderDetail"
accepts_nested_attributes_for :order_details
end
。但使用
:for => :order_details
沒有。它什麼都不渲染。
==求助!
我找到了解決方案。
@ order.order_details是emtpy,因此不會呈現nested_form。
控制器書面方式:
@order.order_details.build
我不明白。當你這樣做的時候,它的工作方式是正確的,當你這樣做的時候是不正確的呢?對不起,我很困惑。 –