# Protect to\_xml and/or disabled other format

**URL:** <https://www.ruby-forum.com/t/protect-to-xml-and-or-disabled-other-format/159304>\
**Category:** Rails\
**Created:** [February 3, 2009, 10:51am UTC](https://www.ruby-forum.com/t/protect-to-xml-and-or-disabled-other-format/159304 "2009-02-03T10:51:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fmh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a698b9/32.png) [@fmh](https://www.ruby-forum.com/u/fmh)\
**Post date:** [February 3, 2009, 10:51am UTC](https://www.ruby-forum.com/t/protect-to-xml-and-or-disabled-other-format/159304/1 "2009-02-03T10:51:24Z")

</div>

hello,  
how protect to\_xml and disabled other format or accpet only html  
format

example : if user type in url www.mysite/controller.xml , i want to  
redirect to another controller.

it’s possible to use a routes to do that ?

---

<div class="post-metadata">

**Author:** ![fmh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a698b9/32.png) [@fmh](https://www.ruby-forum.com/u/fmh)\
**Post date:** [February 3, 2009, 9:39pm UTC](https://www.ruby-forum.com/t/protect-to-xml-and-or-disabled-other-format/159304/2 "2009-02-03T21:39:44Z")

</div>

one way would be a before\_filter, e.g.

class ApplicationController \< ActionController::Base

before\_filter :trap\_xml

def trap\_xml  
if params[:format] == ‘xml’ && params[:action] != ‘my\_xml\_action’  
redirect\_to :controller =\> ‘my\_xml\_controller’, :action =\>  
‘my\_xml\_action’  
end  
end

end

---

<div class="post-metadata">

**Author:** ![fmh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a698b9/32.png) [@fmh](https://www.ruby-forum.com/u/fmh)\
**Post date:** [February 4, 2009, 6:38pm UTC](https://www.ruby-forum.com/t/protect-to-xml-and-or-disabled-other-format/159304/3 "2009-02-04T18:38:01Z")

</div>

yes it’s this.  
thanks
