簡體   English   中英

使用curl和Rails中的兩個模型傳遞xml

[英]passing xml using curl with two models in rails

我想通過curl:

<invoice>
.....
<invoice-details>
<invoice-detail>
....
</invoice-detail>
<invoice-detail>
....
</invoice-detail>
</invoice_details>
</invoice>

順便說一下,我有兩個模型,分別是invoice和invoice_detail。 我有一個發票要傳遞給所有invoice_details的主鍵,以便我可以對它們進行編號。 例如,如果主鍵是200,我也希望發票下的所有詳細信息也具有200外鍵。 我將如何實現這一目標? 非常感謝。

為此操作創建一個xml視圖。 在您的控制器中,我想您具有以下response_to塊:
respond_to do |format|
format.html
format.xml {render :xml => @invoice}

有關創建xml視圖的更多信息,請查看xml builder或此SO問題

要通過curl傳遞它,請在URL中請求.xml,例如:

curl "http://yourapp.com/invoices/2/show.xml"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM