I issued the following curl command to post to the database using REST: curl -i -X POST -d "<heartrate><heartRate>102</ heartRate><sessionID>1002</sessionID><timeStamp>15068</timeStamp></ 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", "<heartrate><hear tRate>102</heartRate><sessionID>1002</sessionID><timeStamp>15068</ 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! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ben Munat
2007-Apr-25 08:43 UTC
Re: problem POSTing with curl and REST using scaffold_resource
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 chirag wrote:> I issued the following curl command to post to the database using > REST: > curl -i -X POST -d "<heartrate><heartRate>102</ > heartRate><sessionID>1002</sessionID><timeStamp>15068</timeStamp></ > 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", > "<heartrate><hear > tRate>102</heartRate><sessionID>1002</sessionID><timeStamp>15068</ > 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! > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---