我的应用程序中的模型是Supplier which has_many indents ,Indent which has_many indent_items ,IndentItem which has_many shipping , Shipment which belongs_to Commercial_invoice , CommercialInvoice which belongs_to supplier & has_many shipping。
以下代码在CommercialInvoiceController的编辑方法中。
def edit
@commercial_invoice = CommercialInvoice.find(params[:id])
@shipments = Shipment.includes(:indent_item => [:indent => :supplier]).where
(:invoice_date => @commercial_invoice.start_date..@commercial_invoice.end_date).where
(:indents => {:supplier_id => @commercial_invoice.supplier_id})
end
在编辑页面中,我使用@shipments 变量来呈现带有复选框的列表。打开编辑页面时,列表呈现良好。但是,如果某些验证失败,则在更新时,编辑页面会再次出现错误,但这次 @shipments 变量是空白的。
所以我检查了控制台,当编辑页面再次出现错误时,代码似乎根本没有再次运行。
我无法弄清楚发生了什么。请在这里帮助我。
谢谢。