Rails 3 respond_to: default format?

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)