繁体   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