简体   繁体   中英

passing xml using curl with two models in rails

I want to pass this through 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. I have a primary key for the invoice to be passed to all the invoice_details so i can id them. for example, if the primary key is 200, i want all the details below that invoice to have a foreign key of 200, too. How am i gonna be able to achieve this? Thanks a lot.

Create an xml view for this action. In your controller, I suppose you have the following respond_to block:
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

To pass it through curl, request the .xml in the url, for example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM