# Restful views

**URL:** <https://www.ruby-forum.com/t/restful-views/150557>\
**Category:** Rails\
**Created:** [October 9, 2008, 8:59pm UTC](https://www.ruby-forum.com/t/restful-views/150557 "2008-10-09T20:59:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [October 9, 2008, 8:59pm UTC](https://www.ruby-forum.com/t/restful-views/150557/1 "2008-10-09T20:59:39Z")

</div>

Hi \*,  
I’m writing a Restful service that should map a pre-existing  
partially restful site.  
What I find confusing is how to display models in my views. I’m  
writing all XML in builder using the respond\_to API, but everything I  
found on the net uses the to\_xml method of model’s instances, and  
that’s not my case because I don’t want to display every attribute of  
my models.  
Problem is that to\_xml for example gives type informations for most  
(not all) attributes.  
Is there a place where this is documented ? How should I write my  
builder views ? Try a to\_xml and rewrite ? Ouch … 😛

TIA, much appreciated,  
ngw

---

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [October 11, 2008, 1:42am UTC](https://www.ruby-forum.com/t/restful-views/150557/2 "2008-10-11T01:42:59Z")

</div>

Hi,  
In your controller you can specify what you want to be included in the  
xml and filter out the stuff you don’t want to be there. For example:

render :xml =\> @survey\_response.to\_xml( :dasherize =\> false,  
:include =\> {  
:user =\>  
{:include =\>  
{:city =\>  
{:include =\>  
{:state =\> {}  
}  
}  
}  
},  
:answers =\>  
{:include =\>  
{:question =\> {}, :choice =\> {}  
}  
}  
}  
)

that’s part of controller i have for one of my apps where i feed back  
to the xml the answers given by a user who filled a form. And i choose  
to include the city/state information with the answers, whereas if i  
do the following:

render :xml =\> @survey\_response.to\_xml( :dasherize =\> false,  
:include =\> {  
:user =\>  
{:include =\>  
{:city =\>  
{:include =\>  
{:state =\> {}  
}  
}  
}  
}  
}  
)

I would be just including the city/state info and leaving out the  
answers. You could do something similar for your model.

I hope this is helpful

On Oct 9, 2:58 pm, Nicholas W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
