Reputation: 93196
here is my code in a controller
respond_to do |format|
format.html
format.xml { render :xml => @menus }
end
when i type "http://192.168.210.136:3000" then it renders the html version.
but how do i request the xml version? i tried http://192.168.210.136:3000.xml and http://192.168.210.136:3000/index.xml with no luck.
thanks!
Upvotes: 0
Views: 712
Reputation: 9093
Suggest you give http://guides.rubyonrails.org/routing.html#formats-and-respond-to a good read
Upvotes: 1
Reputation: 653
If you wish to return XML - by default - in your root route, you might need to change your routes.rb to make it more explicit, like this (rails 3 example):
Sandbox::Application.routes.draw do |map|
root :to => "static#index", :format => :xml
end
On rails 2.3.x you can pass your routes a defaults hash, like this:
map.connect 'photos/:id', :controller => 'photos',
:action => 'show',
:defaults => { :format => 'jpg' }
For more information regarding the rails router, please check the official Rails guides at: http://guides.rubyonrails.org/routing.html
Upvotes: 1
Reputation: 7477
In the general case you add the .xml
suffix to your URL to tell the Rails responder what you want. Your controller logic is the correct way to handle the incoming request.
E.g. A User
show
for ID=1 in XML would look like this:
Upvotes: 1