# Best respond\_to design practice

**URL:** <https://www.ruby-forum.com/t/best-respond-to-design-practice/140392>\
**Category:** Rails\
**Created:** [June 13, 2008, 3:11pm UTC](https://www.ruby-forum.com/t/best-respond-to-design-practice/140392 "2008-06-13T15:11:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rickf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@rickf](https://www.ruby-forum.com/u/rickf)\
**Post date:** [June 13, 2008, 3:11pm UTC](https://www.ruby-forum.com/t/best-respond-to-design-practice/140392/1 "2008-06-13T15:11:47Z")

</div>

Hi All,

I am in the middle of building a web service using the standard:

```
# Return the appropriate response based on the type
respond_to do |format|
  format.html { render :layout => 'some layout' }
  format.xml { render :xml => @data.to_xml }
end

```

My question is the following possible…

I’d like to insert some custom XML tags before all object.to\_xml data  
which are returned by the web service. For example:

- contains a numeric result code  
\<result\_msg\>\</result\_msg\> - contains result string  
followed by the object to XML data

Is this possible?

Also, can you filter out specific fields from the response XML?

Thanks,  
Rick

---

<div class="post-metadata">

**Author:** ![rickf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@rickf](https://www.ruby-forum.com/u/rickf)\
**Post date:** [June 13, 2008, 3:27pm UTC](https://www.ruby-forum.com/t/best-respond-to-design-practice/140392/2 "2008-06-13T15:27:34Z")

</div>

From the API,  
[http://api.rubyonrails.org/classes/ActiveRecord/XmlSerialization.html](http://api.rubyonrails.org/classes/ActiveRecord/XmlSerialization.html)

“Builds an XML document to represent the model. Some configuration is  
availble through options, however more complicated cases should use  
override ActiveRecord‘s to\_xml.”

This should get you started.

best.  
mike
