title: override to_xml to limit fields returned
body: <p>using ruby 1.9.2 and rails 3, i would like to limit the fields returned when a record is accessed as json or xml (the only two formats allowed).  </p>
  
  <p><a href="http://ryandaigle.com/articles/2009/8/6/what-s-new-in-edge-rails-cleaner-restful-controllers-w-respond_with" rel="nofollow">this</a> very useful post introduced me to respond_with and i found somewhere online that a nice way to blanket allow/deny some fields is to override as_json or to_xml for the class and set :only or :except to limit fields.</p>
  
  <p>example:</p>
  
  <pre><code>class Widget &lt;  ActiveRecord::Base
    def as_json(options={})
      super(:except =&gt; [:created_at, :updated_at])
    end
  
    def to_xml(options={})
      super(:except =&gt; [:created_at, :updated_at])
    end
  end
  
  class WidgetsController &lt; ApplicationController
    respond_to :json, :xml
  
    def index
      respond_with(@widgets = Widgets.all)
    end
  
    def show
      respond_with(@widget = Widget.find(params[:id]))
    end
  end
  </code></pre>
  
  <p>this is exactly what i am looking for and works for json, but for xml "index" (GET /widgets.xml) it responds with an empty Widget array.  if i remove the to_xml override i get the expected results.  am i doing something wrong, and/or why does the Widgets.to_xml override affect the Array.to_xml result?</p>
  
  <p>i can work around this by using</p>
  
  <pre><code>respond_with(@widgets = Widgets.all, :except =&gt; [:created_at, :updated_at])
  </code></pre>
  
  <p>but do not feel that is a very DRY method.</p>