# Please help

**URL:** <https://www.ruby-forum.com/t/please-help/126436>\
**Category:** Rails\
**Created:** [January 18, 2008, 9:00am UTC](https://www.ruby-forum.com/t/please-help/126436 "2008-01-18T09:00:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haris\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Haris\_G](https://www.ruby-forum.com/u/Haris_G)\
**Post date:** [January 18, 2008, 9:00am UTC](https://www.ruby-forum.com/t/please-help/126436/1 "2008-01-18T09:00:27Z")

</div>

Hello all,

I have developed a RESTFul webservice in RoR. Here under is the  
controller

* * *

class PeopleController \< ApplicationController  
def index  
list  
render :action =\> ‘list’  
end

# GETs should be safe (see

[URIs, Addressability, and the use of HTTP GET and POST](http://www.w3.org/2001/tag/doc/whenToUseGet.html))  
verify :method =\> :post, :only =\> [ :destroy, :create, :update  
],  
:redirect\_to =\> { :action =\> :list }

def list  
# wants is determined by the http Accept header in the request  
@people = Person.find\_all  
respond\_to do |wants|  
wants.html  
wants.xml { render :xml =\> @people.to\_xml }  
end  
end

def show  
@person = Person.find(params[:id])  
respond\_to do |wants|  
wants.html  
wants.xml { render :xml =\> @person.to\_xml }  
end  
end

def new  
@person = Person.new  
end

def create  
@person = Person.new(params[:person])  
if @person.save  
flash[:notice] = ‘Person was successfully created.’  
redirect\_to :action =\> ‘list’  
else  
render :action =\> ‘new’  
end  
end

def edit  
@person = Person.find(params[:id])  
end

def update  
@person = Person.find(params[:id])  
if @person.update\_attributes(params[:person])  
flash[:notice] = ‘Person was successfully updated.’  
redirect\_to :action =\> ‘show’, :id =\> @person  
else  
render :action =\> ‘edit’  
end  
end

## def destroy Person.find(params[:id]).destroy redirect\_to :action =\> ‘list’ end end

and I have another application that consumes this webservice. The  
controller  
for this webservice is

* * *

def index  
Net::HTTP.start(‘localhost’, 3000) do |http|  
response = http.get(‘/people/list’, ‘Accept’ =\> ‘text/xml’)  
@body = response.body  
end  
end

* * *

can anyone please help me how to parse the response that is saved in  
body.  
Body variable has 5 fields namely ID, FNAME, LNAME, EMAIL, PHONE. and I  
want  
to display all fields seperately. Please reply as soon as possible.

I have also tried doing

* * *

## url = “[http://localhost:3000/people/list](http://localhost:3000/people/list)” result = Net::HTTP.get(URI(url)) @body = REXML::Document.new result

and then in my view I tried

* * *

## \<removed\_email\_address@domain.invalid\_element do |res|%\> \<%=res[0].text.to\_s%\> —\> uptil res[4]. \<%end%\>

The error I get is, undefined method text. and if I remove the text and  
only  
write \<%=res.to\_s%\>, it displays some random numbers like 62, 111 etc

Please reply back as soon as possible

–  
Regards

Haris G.

---

<div class="post-metadata">

**Author:** ![Haris\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Haris\_G](https://www.ruby-forum.com/u/Haris_G)\
**Post date:** [January 18, 2008, 9:30am UTC](https://www.ruby-forum.com/t/please-help/126436/2 "2008-01-18T09:30:52Z")

</div>

Rails 2.0 has a framework called ActiveResource that will work with any  
restful service.

---

<div class="post-metadata">

**Author:** ![Haris\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Haris\_G](https://www.ruby-forum.com/u/Haris_G)\
**Post date:** [January 18, 2008, 10:50am UTC](https://www.ruby-forum.com/t/please-help/126436/3 "2008-01-18T10:50:52Z")

</div>

and How does it work…Actually I have a deadline to meet :(. currently  
Im  
using rails 1.2.6. There must be a way to solve this problem in this  
version. Anyone ??

I have the data, its just that I have to parse it to extract all the  
fields  
from it. I hope I have made myself clear on what problem I am facing

On Jan 18, 2008 1:30 PM, Keynan P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## Rails 2.0 has a framework called ActiveResource that will work with any restful service.
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Regards

Haris G.

---

<div class="post-metadata">

**Author:** ![Haris\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@Haris\_G](https://www.ruby-forum.com/u/Haris_G)\
**Post date:** [January 18, 2008, 10:54am UTC](https://www.ruby-forum.com/t/please-help/126436/4 "2008-01-18T10:54:58Z")

</div>

Another observation…I just tried doing this

@body = response.body.split(’ ') // that is I split the string using  
space  
as the delimiter

And in my view I wrote

\<removed\_email\_address@domain.invalid do |res|%\>  
\<%=res%\>  
  
\<%end%\>

This gives a very strange output. Something like

* * *

version=“1.0”  
encoding=“UTF-8”?\>

removed\_email\_address@domain.invalid  
Haris

type=“integer”\>1  
Gulzar  
12345678901

removed\_email\_address@domain.invalid  
Ahmad

type=“integer”\>2  
Nawaz  
12345678912

* * *

This is giving the ID, FNAME, LNAME, EMAIL, and PHONE. But is also  
giving  
other things (as can be seen above). Any suggestions ?

On Jan 18, 2008 2:49 PM, Haris G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> Regards
> 
> Haris G.

–  
Regards

Haris G.
