fabrik42/acts_as_api

How to remove type='array' and type='integer' in xml response

hebing0625 opened this issue · 2 comments

@fabrik42:

In some cases, xml response maybe look like:

 <users type="array">
  <user>
    <first-name>Me</first-name>
    <duration-in-seconds type="integer">4</duration-in-seconds>
  </user>
</users>

But I don't need the type='array' and type='integer', is there anyway to remove them? Just like this:

<users>
  <user>
    <first-name>Me</first-name>
    <duration-in-seconds>4</duration-in-seconds>
  </user>
</users>

acts_as_api uses the internal renderers of Rails itself. But you can exclude the type information there by passing the :skip_types option to the renderer (acts_as api will pass it on).

For example with the ActsAsApi::Responder

respond_with @users, :api_template => :name_only, :skip_types => true    

Or with a common controller

respond_to do |format|
  format.xml  { render_for_api :name_only, :xml => @users, :skip_types => true }
end

see here for the docs: http://api.rubyonrails.org/classes/ActiveRecord/Serialization.html#method-i-to_xml

I'm closing the issue for now, let me know if I can help you :)

Cheers,

Chris

Thank you very much. :)