# Hiding resource fields

**URL:** <https://www.ruby-forum.com/t/hiding-resource-fields/125359>\
**Category:** Rails\
**Created:** [January 8, 2008, 3:38pm UTC](https://www.ruby-forum.com/t/hiding-resource-fields/125359 "2008-01-08T15:38:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubenfonseca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@rubenfonseca](https://www.ruby-forum.com/u/rubenfonseca)\
**Post date:** [January 8, 2008, 3:38pm UTC](https://www.ruby-forum.com/t/hiding-resource-fields/125359/1 "2008-01-08T15:38:31Z")

</div>

Hi!

I’ve a Rails 2.0 site using RESTful resources. I added JSON support  
too, so the model can be get through HTML (using my views), XML and  
JSON (using .to\_xml and .to\_json)

The problem is that I want to hide some fields on the XML and JSON  
output (the HTML isn’t a problem, because I control what I want to  
show on the view). For example, on the User model, I don’t want to  
send the ‘password’ field via XML or JSON.

What’s the best way to do this, and do it DRY around all RESTful  
methods? The only solution I was thinking is to write xml.builder and  
json.builder but there should be a easy way 🙂

Greetings,  
Ruben

---

<div class="post-metadata">

**Author:** ![rubenfonseca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@rubenfonseca](https://www.ruby-forum.com/u/rubenfonseca)\
**Post date:** [January 8, 2008, 3:59pm UTC](https://www.ruby-forum.com/t/hiding-resource-fields/125359/2 "2008-01-08T15:59:06Z")

</div>

On 8 Jan 2008, at 14:36, Ruben F. wrote:

> Hi!
> 
> I’ve a Rails 2.0 site using RESTful resources. I added JSON support  
> too, so the model can be get through HTML (using my views), XML and  
> JSON (using .to\_xml and .to\_json)

to\_xml/to\_json take :except or :only options

Fred
