# Problem POSTing with curl and REST using scaffold\_resource

**URL:** <https://www.ruby-forum.com/t/problem-posting-with-curl-and-rest-using-scaffold-resource/92872>\
**Category:** Rails\
**Created:** [April 25, 2007, 8:23am UTC](https://www.ruby-forum.com/t/problem-posting-with-curl-and-rest-using-scaffold-resource/92872 "2007-04-25T08:23:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chirag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@chirag](https://www.ruby-forum.com/u/chirag)\
**Post date:** [April 25, 2007, 8:23am UTC](https://www.ruby-forum.com/t/problem-posting-with-curl-and-rest-using-scaffold-resource/92872/1 "2007-04-25T08:23:40Z")

</div>

I issued the following curl command to post to the database using  
REST:  
curl -i -X POST -d “102\</  
heartRate\>100215068\</  
heartrate\>” [http://localhost:3000/heartrates](http://localhost:3000/heartrates)

I have tested the GET (with curl also) and it works fine!  
curl [http://localhost:3000/heartrates/45](http://localhost:3000/heartrates/45)

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  
=-=-=-=-=  
The POST command makes it to the Rails controller and actually inserts  
a record into the database, but it inserts all NULLs in the fields  
(instead of above specified values) as shown by the following log:

Processing HeartratesController#create (for 127.0.0.1 at 2007-04-24  
13:17:10) [POST]  
Session ID: 36bc0c6a51f5fb79f4086700776e0aed  
Parameters: {“action”=\>“create”, “controller”=\>“heartrates”,  
“102100215068\</  
timeStamp\>\</he  
artrate\>”=\>“”}  
â†[4;36;1mHeartrate Columns (0.031000)â†[0m â†[0;1mSHOW FIELDS FROM  
heartratesâ†  
[0m  
â†[4;35;1mSQL (0.016000)â†[0m â†[0mBEGINâ†[0m  
â†[4;36;1mSQL (0.000000)â†[0m â†[0;1mINSERT INTO heartrates  
(`timeStamp`, `hear tRate`, `sessionID`) VALUES(NULL, NULL, NULL)â†[0m  
â†[4;35;1mSQL (0.031000)â†[0m â†[0mCOMMITâ†[0m  
Completed in 0.09300 (10 reqs/sec) | Rendering: 0.00000 (0%) | DB:  
0.07800 (83%)  
| 201 Created [[http://localhost/heartrates](http://localhost/heartrates)]

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  
=-=-=-=-=

This is the create() method (that handles the POST request) in the  
controller (generated by scaffold\_resource)

# POST /heartrates

# POST /heartrates.xml

def create  
@heartrate = Heartrate.new(params[:heartrate])  
respond\_to do |format|  
if @heartrate.save  
flash[:notice] = ‘Heartrate was successfully created.’  
#format.html { redirect\_to heartrate\_url(@heartrate) }  
format.xml { head :created, :location =\>  
heartrate\_url(@heartrate) }  
else  
#format.html { render :action =\> “new” }  
format.xml { render :xml =\> @heartrate.errors.to\_xml }  
end  
end  
end

Thanks in advance for any suggestions!

---

<div class="post-metadata">

**Author:** ![chirag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@chirag](https://www.ruby-forum.com/u/chirag)\
**Post date:** [April 25, 2007, 10:47am UTC](https://www.ruby-forum.com/t/problem-posting-with-curl-and-rest-using-scaffold-resource/92872/2 "2007-04-25T10:47:19Z")

</div>

I think what you’re missing is setting the Content-type header to  
text/xml… not positive, but I think that might trigger rails to parse  
the xml into a params hash. You set a header with the -H option.

I’ve never used the -i or -X options… will have to check those out.  
You might also want to use the -v option which gives you a lot more  
feedback on the command line as to what’s happening.

And of course, there’s always checking the development.log since the  
incoming params are dumped in there.

b
