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
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 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]
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=-=-=-=-=
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!