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
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"
result = Net::HTTP.get(URI(url))
@body = REXML::Document.new result
---------------------------------------------------------------------------------------------------------
and then in my view I tried
---------------------------------------------------------------------------------------------------------
<%@body.root.each_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 Gulzar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Rails 2.0 has a framework called ActiveResource that will work with any restful service. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Pratt <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Gulzar --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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
<%@body.each do |res|%>
<%=res%><br>
<%end%>
This gives a very strange output. Something like
---------------------------------------------------------------------------------------------------------
version="1.0"
encoding="UTF-8"?>
harisgulzar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Haris
type="integer">1
Gulzar
12345678901
ahmad-M/39claqbm0@public.gmane.org
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 Gulzar
<harisgulzar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> 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 Pratt
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
> 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 Gulzar
--
Regards
Haris Gulzar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---