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.