views:

22

answers:

0

In Rails, we can

respond_to do |format|
  format.html
  format.json { render :json => @data }
end

so it knows to automatically show the @data in json format, but when it is xml, it needs to be

  format.xml { render :xml => @data.to_xml }

why does it need to explicitly convert @data into XML? Can't it be just like json's case? to_json and to_xml actually just convert the object into a string, so it looks like in both cases, we can do the convert automatically?