Thursday, 27 September 2007

Restricting to_xml RESTfully

If you want to restrict the XML representation of your model to just a few fields, use:
  def to_xml(options={})
options[:only] = [:id, :name]
super(options)
end

Replacing the array with whatever fields you want to restrict the representation to.

A couple of the other examples out there break the :index XML representation because they don't pass on the upstream options. This one is kind to REST.