Posting xml to create new record


I noticed that with the latest version of Rails, scaffolding in the
controller already has resourceful methods. Based on the comments in
the code, it seems that all of this is built in, but I’m having some
trouble with creating new records by posting xml data.

I have a SubversionRepository model and SubversionRepositories
controller. When I access /subversion_repositories.xml I get a list of
repositories in a format like:

<?xml version="1.0" encoding="UTF-8"?> ... repo1 group1 ...

Based on this format, I tried posting a new repository to the address
/subversion_repositories.xml using the following xml.

newrepo newgroup

I store this in the file repo.xml and post it using the following code.

require ‘net/http’
require ‘uri’
require ‘rexml/document’

file = “repo.xml”
xml_document =

puts “sending XML in http POST”
http_client =‘localhost’, 3000)
http_result =‘/subversion_repositories.xml’,
puts "result type: " +
puts "result: " + http_result.body.to_s

The script returns the following output.

sending XML in http POST
result type: Net::HTTPClientError
result: <?xml version="1.0" encoding="UTF-8"?>

Name can’t be blank
Group can’t be blank

The log file has an entry similar to the following.

Processing SubversionRepositoriesController#create (for XXXXX at
2008-03-13 14:54:00) [POST]
Session ID: XXXXX
Parameters: {“format”=>“xml”, “action”=>“create”,
“controller”=>“subversion_repositories”, “\n
newrepo\n newgroup\n <created-at
type”=>“‘datetime’ nil=‘true’/>\n 2008-03-12T16:15:51-05:00\n
Completed in 0.01600 (62 reqs/sec) | Rendering: 0.00000 (0%) | DB:
0.00000 (0%) | 422 Unprocessable Entity

Does anyone know what I’m doing wrong? Does this functionality not come
built in?

Thanks for your help.

[email protected] wrote:

Have you tried
headers = {‘Content-Type’ => ‘text/xml’}
http_result =’/subversion_repositories.xml’,

That is exactly what I needed. Thanks!

Have you tried
headers = {‘Content-Type’ => ‘text/xml’}
http_result =‘/subversion_repositories.xml’,

On Mar 13, 1:10 pm, Justin J. [email protected]