I'm not really sure if this is best practice or not, but usually what I like to do is to leave the routes open to respond_to (i.e. by appending .:format
to the end), but only use it in the controllers when it's necessary.
Example:
routes.rb
map.connect :controller/:action/:id.:format
model_controller.rb
# Return a collection of model objects
def action_with_multiple_responses
@models = Model.all
respond_to do |format|
format.html #=> action_with_multiple_responses.html
format.xml { render :xml => @models }
end
end
# Return the first model object
def action_with_one_response
@model = Model.first
end
That way, you aren't cluttering up your action_with_one_response
method with an unnecessary block, but you also have set yourself up quite nicely if you want to someday return your object in xml, json, etc.