def format_resource resource, format
        if resource.is_a?(ActiveRecord::Base) and not resource.valid?
          resource.errors.send "to_#{format}"
        else
          resource.send "to_#{format}"
        end
      end
def format_resource resource, format
        if resource.is_a?(ActiveRecord::Base) and not resource.valid?
          resource.errors.send "to_#{format}"
        else
          resource.send "to_#{format}"
        end
      end
=============================================================================