views:

423

answers:

1

the code

respond_to do |format|
  format.html
  format.json { render :json => @switches }
  format.xml { render :xml => @switches.to_xml }
  format.all { render :text => "only HTML, XML, and JSON format are supported at the moment." }
end

the above will work in Rails 2.2.2. But in Rails 3, getting controller/index.html or index on the browser will both fall into the last line: "only HTML and JSON format are supported at the moment."

The only Rails doc I can find on this is

http://api.rubyonrails.org/classes/ActionController/MimeResponds/ClassMethods.html#method-i-respond_to

which current only states:

respond_to :html, :xml, :json

but they need separate templates for json and xml, and can't handle the "only HTML and JSON format are supported at the moment" case.

A: 

You may find it useful to watch this episode of railscasts, which illustrates the changes to controllers in Rails 3 and in particular the changes to the responder class (putting respond_to in the controller class itself and only using respond_with @object in the action):

http://railscasts.com/episodes/224-controllers-in-rails-3

svilenv