0

我正在使用 rails 2.3.5、ruby 1.9.3、rubygems 1.8.24 和 mac os x lion

我正在使用 cURL 传递这个文件“invoice.xml.erb”:

<invoice>
....
<invoice_detail>
....
</invoice_detail>
</invoice>

我期望填写发票字段以及 invoice_details 字段,但是当我通过 cURL 命令时,仅填写发票字段,并发生此错误:警告:无法批量分配这些受保护的属性:inventoryDocId,invoice_detail

这是我的模型:

发票.rb

class Invoice < ActiveRecord::Base
set_table_name "inventoryDocHeader"
set_primary_key "inventoryDocId"
has_many :invoice_detail, :foreign_key => "inventoryDocId"
attr_accessible :inventoryDocId, :originDocId, :siteCode, :transCode, :typeCode, :docCode,    :partyTerms,:locationCode, :otherCharges, :grossPrice, :netPrice, :amountPaid, :amountPending, :amountReturned, :RSiteCode, :RInventoryDocId, :RDocCode, :ROriginDocId, :batchCode, :partyCharges, :partyShipmentTermsText, :estimateVolume, :originCountryId, :consigneeName, :consigneeAddress1, :consigneeAddress2, :consigneeAddress3, :notifyPartyName, :notifyPartyAddress1, :notifyPartyAddress2, :notifyPartyAddress3

 end

invoice_detail.rb

class InvoiceDetail < ActiveRecord::Base
set_table_name "inventoryDocDetail"
belongs_to :invoice, :foreign_key => "inventoryDocId"
attr_accessible :inventoryDocId, :lineNumber, :parentLineNumber, :productCode,   :actualQuantity, :unitCode, :contentQuantity, :cost, :price, :commission, :factorRate, :referenceLineNumber
end

欢迎任何建议。谢谢!

4

1 回答 1

0

:invoice_detail_attributes对于第一个错误,您必须添加到 attr_accessible 命令。对于第二个,您是从 Invoice 还是 InvoiceDetails 模型中获取的?

于 2012-05-23T07:47:27.297 回答