mustang (3) [Avatar] Offline
#1
Hi,

I'm getting "attempted adding second root element to document" from rails side of my app all the time when enter username and password then hit login.

Is there any errata about the book. I suspect it's because of the rails version (which is 2.0.2)

Here's the complete error.

attempted adding second root element to document
Line:
Position:
Last 80 unconsumed characters:
test</password>
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rexml/parsers/treeparser.rb:90:in `parse'
....
mustang (3) [Avatar] Offline
#2
Re: Error in iteration 3 adding login functionality
I've made some progress and worked around the problem. But it is still not clear and I'm not gonna feel comfortable until I find an answer. Iteration 3 is still in early stages without being RESTful so I'm looking forward to find an answer

The code in the book says, send a hash/dict etc. as parameter. As you'd expect from a rails controller.

svnLoginAccount.send({login: loginTI.text, password: passwordTI.text})

which in ruby should mean;
Parameters: {:login => 'ludwig', :password => 'foooo'}

But this BREAKS the server with internal error. It cannot parse the request. The service tag is as below. Nothing fancy.

<mx:HTTPService >
id="svnLoginAccount"
url="/sessions/create_xml"
method="POST"
resultFormat="e4x"
contentType="application/xml"
result="handleAccountLoginResult(event)"/>

The error says there cannot be more than one root. So I wrapped parameters (login and passwd) in a session key and used the one below.

svnLoginAccount.send({session : {login: loginTI.text, password: passwordTI.text}})

translated to
Parameters: {:session => {:login => 'ludwig', :password => 'foooo'}}

It worked. Of course you need to modify controller code and replace params[:login] and params[:password] with params[:session][:login] and params[:session][:password]

For the time being, I've got no clue how and why rails server breaks. This workaround also totally sucks. I must not be forced to have all parameters under one root. Hopefully I'll understand as I read on.
nachbar (45) [Avatar] Offline
#3
Re: Error in iteration 3 adding login functionality
The code in the book works with Rails 2.1, which I am using. The error in your code is the

contentType="application/xml"

paramter, which is not in the book (see page 86)

If you remove that, your code will work.

James Nachbar
http://www.plastic.org
Shasto (1) [Avatar] Offline
#4
Re: Error in iteration 3 adding login functionality
Hi,

Rails Newbie also but I after reverting back to Rails 2.0.1 I found the following....
1) I had forgotten to attach the events to the pom namespaces on pge 88 (7 and smilie
2) After I had done this the Login worked ok but I still had problems on the Create - examining the Mongrel output it seems it was looking for a create_xml.html.erb in app/views/user so I created a copy of new.html.erb and named it create_xml.html.erb and it worked.

Not sure of the reason why but just thought you might want to know.