views:

110

answers:

1

I am working on a RoR project which outputs XML to RESTful requests. The problem is it includes the "updated-at" and "created-at" fields in the output.

I have tried using:

:exclude -> [ :created_at, :updated_at ] 

and

:exclude -> [ 'created-at', 'updated-at' ]

but the output still renders them. How do I exclude them from the rendering without these?

+2  A: 

The option you want is called :except, not :exclude. For example:

obj.to_xml(:except => [ :created_at, :updated_at ])

For more info, see the Rails API docs for this method.

Alex Reisner
This worked perfectly. What's more, I has discovered that it applies the `:except` to the entire xml, including any `:include`'s. Cool. Exactly what I needed.
Ash