Problem POSTing with curl and REST using scaffold_resource

I issued the following curl command to post to the database using
curl -i -X POST -d “102</
heartrate>” http://localhost:3000/heartrates

I have tested the GET (with curl also) and it works fine!
curl 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 at 2007-04-24
13:17:10) [POST]
Session ID: 36bc0c6a51f5fb79f4086700776e0aed
Parameters: {“action”=>“create”, “controller”=>“heartrates”,
←[4;36;1mHeartrate Columns (0.031000)←[0m ←[0;1mSHOW FIELDS FROM
←[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]


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])
respond_to do |format|
flash[:notice] = ‘Heartrate was successfully created.’
#format.html { redirect_to heartrate_url(@heartrate) }
format.xml { head :created, :location =>
heartrate_url(@heartrate) }
#format.html { render :action => “new” }
format.xml { render :xml => @heartrate.errors.to_xml }

Thanks in advance for any suggestions!

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.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs