What that says is, “if the client wants HTML or JS in response to this
action, just respond as we would have before, but if the client wants XML,
return them the list of people in XML format.” (Rails determines the
desired response format from the HTTP Accept header submitted by the
client.)

Supposing you have an action that adds a new person, optionally creating
their company (by name) if it does not already exist, without web-services,
it might look like this:

If the client wants HTML, we just redirect them back to the person list. If
they want JavaScript, then it is an Ajax request and we render the
JavaScript template associated with this action. Lastly, if the client
wants XML, we render the created person as XML, but with a twist: we also
include the person's company in the rendered XML, so you get something
like this:

This is because the incoming XML document (if a web-service request is in
process) can only contain a single root-node. So, we have to rearrange
things so that the request looks like this (url-encoded):

In other words, we make the request so that it operates on a single
entity's person. Then, in the action, we extract the company data from
the request, find or create the company, and then create the new person
with the remaining data.

Note that you can define your own XML parameter parser which would allow
you to describe multiple entities in a single request (i.e., by wrapping
them all in a single root node), but if you just go with the flow and
accept Rails' defaults, life will be much easier.

If you need to use a MIME type which isn't supported by default, you
can register your own handlers in
config/initializers/mime_types.rb as follows.

Mime::Type.register "image/jpg", :jpg

Respond to also allows you to specify a common block for different formats
by using any:

The request variant is a specialization of the request format, like
:tablet, :phone, or :desktop.

We often want to render different html/json/xml templates for phones,
tablets, and desktop browsers. Variants make it easy.

You can set the variant in a before_action:

request.variant = :tablet if request.user_agent =~ /iPad/

Respond to variants in the action just like you respond to formats:

respond_to do |format|
format.html do |variant|
variant.tablet # renders app/views/projects/show.html+tablet.erb
variant.phone { extra_setup; render ... }
variant.none { special_setup } # executed only if there is no variant set
end
end