Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3805674
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:42:55+00:00 2026-05-19T14:42:55+00:00

I am converting a Rails 2 application to Rails 3. I currently have a

  • 0

I am converting a Rails 2 application to Rails 3. I currently have a controller set up like the following:

class Api::RegionsController < ApplicationController
  respond_to :xml, :json
end

with and an action that looks like the following:

def index
  @regions = Region.all

  respond_with @regions  
end

The implementation is pretty straightforward, api/regions, api/regions.xml and api/regions.json all respond as you would expect. The problem is that I want api/regions by default to respond via XML. I have consumers that expect an XML response and I would hate to have them change all their URLs to include .xml unless absolutely necessary.

In Rails 2 you would accomplish that by doing this:

respond_to do |format|
  format.xml { render :xml => @region.to_xml }
  format.json { render :json => @region.to_json }
end

But in Rails 3 I cannot find a way to default it to an XML response. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:42:56+00:00Added an answer on May 19, 2026 at 2:42 pm

    If I understand what you are trying to do, you probably can solve the issue by setting the default resource format to XML. This will allow your users to make requests using ‘api/regions’ and have the response default to XML. Take a look at look at the ‘Controller Namespaces and Routing’ and the ‘Defining Defaults’ sections at:

    http://guides.rubyonrails.org/routing.html

    You could do something like the following in routes.rb:

    namespace "api" do
      resources :regions, :defaults => { :format => 'xml' }
    end
    

    Then you should be able to have the following work for your controller methods:

    class Api::RegionsController < ApplicationController
      respond_to :xml, :json
    
      def index 
        respond_with(@regions = Region.all)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm converting an application to use Java 1.5 and have found the following method:
I'm converting a part of a rails application to its own sinatra application. It
I have a fairly complex Rails app built on top of Twitter's API, and
I'm looking at converting our Rails 2.3 application to correctly handle time zones (at
I'm starting to use simple_form for a rails application, and while converting some of
I'm having some difficulties converting this old mailer api to rails 3: content_type multipart/mixed
I'm currently converting my 2.3.8 rails app to 3.1. Error: wrong number of arguments
I was having some trouble converting the following route from rails 2 way to
I've been converting my Rails 2.3.9 application to Rails 3.0 and everything has been
I have a Rails application where people can use an in browser sound editor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.