Please help

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)
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
result = Net::HTTP.get(URI(url))
@body = REXML::Document.new result

and then in my view I tried


<[email protected]_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.

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

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. [email protected]
wrote:

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

Posted via http://www.ruby-forum.com/.


Regards

Haris G.

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

<[email protected] do |res|%>
<%=res%>

<%end%>

This gives a very strange output. Something like


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

[email protected]
Haris

type=“integer”>1
Gulzar
12345678901

[email protected]
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. [email protected] wrote:


Regards

Haris G.


Regards

Haris G.