Forum: Ruby on Rails problem POSTing with curl and REST using scaffold_resource

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bbdc298cd824989df148bc5312ab4bc3?d=identicon&s=25 chirag (Guest)
on 2007-04-25 08:23
(Received via mailing list)
I issued the following curl command to post to the database using
curl -i -X POST -d "<heartrate><heartRate>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!
8310c5a7c769345114597bcdef111488?d=identicon&s=25 Ben Munat (Guest)
on 2007-04-25 10:47
(Received via mailing list)
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 topic is locked and can not be replied to.