简体   繁体   English

使用curl和Rails中的两个模型传递xml

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

I want to pass this through curl: 我想通过curl:

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

I have two models, invoice and invoice_detail, which are associated, by the way. 顺便说一下,我有两个模型,分别是invoice和invoice_detail。 I have a primary key for the invoice to be passed to all the invoice_details so i can id them. 我有一个发票要传递给所有invoice_details的主键,以便我可以对它们进行编号。 for example, if the primary key is 200, i want all the details below that invoice to have a foreign key of 200, too. 例如,如果主键是200,我也希望发票下的所有详细信息也具有200外键。 How am i gonna be able to achieve this? 我将如何实现这一目标? Thanks a lot. 非常感谢。

Create an xml view for this action. 为此操作创建一个xml视图。 In your controller, I suppose you have the following respond_to block: 在您的控制器中,我想您具有以下response_to块:
respond_to do |format|
format.html
format.xml {render :xml => @invoice}

For more on creating xml views, check out xml builder or this SO question 有关创建xml视图的更多信息,请查看xml builder或此SO问题

To pass it through curl, request the .xml in the url, for example: 要通过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