Rails and REST

Hello,

I was wondering how do I use the respond_to xml ?

class PeopleController < ApplicationController
def index
@peope = People.find(:all)
respond_to do | request |
request.html { }
request.xml { render :xml => @people…to_xml(:except => [:id])
}
end
end
end

I tried with this and I always get execution timeout?

result = Net::HTTP.get(URI(‘http://localhost:3000/people’))
@people = REXML::Document.new(result)

How can I get the my index to response with XML?

Thanks for any help :slight_smile:

On Nov 3, 2007, at 1:48 PM, Jamal S. wrote:

class PeopleController < ApplicationController
def index
@peope = People.find(:all)
respond_to do | request |
request.html { }
request.xml { render :xml => @people…to_xml(:except =>
[:id])

The couple of dots is a typo.

result = Net::HTTP.get(URI(‘http://localhost:3000/people’))
@people = REXML::Document.new(result)

How can I get the my index to response with XML?

If you have declared

map.resources :people

then you can specify the desired “xml” format this way:

http://localhost:3000/people.xml

– fxn

On 3 Nov 2007, at 12:48, Jamal S. wrote:

I tried with this and I always get execution timeout?

result = Net::HTTP.get(URI(‘http://localhost:3000/people’))
@people = REXML::Document.new(result)

Are you doing this from the same rails app? in dev mode you typically
only have 1 mongrel, if 1 is busy executing the above code that leaves
no one to handle the request you;re making.

On top of that you need to tell it you want xml. You can either do
this by setting the Accept header or by saying you want people.xml
(assuming you’ve got the standard routes setup)

Fred