# Filtering routes based on format

**URL:** <https://www.ruby-forum.com/t/filtering-routes-based-on-format/177588>\
**Category:** Rails\
**Created:** [October 20, 2009, 5:24pm UTC](https://www.ruby-forum.com/t/filtering-routes-based-on-format/177588 "2009-10-20T17:24:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattwynne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecc23a/32.png) [@mattwynne](https://www.ruby-forum.com/u/mattwynne)\
**Post date:** [October 20, 2009, 5:24pm UTC](https://www.ruby-forum.com/t/filtering-routes-based-on-format/177588/1 "2009-10-20T17:24:25Z")

</div>

Hi,

We’ve had some requests though for nonsense URLs which have slipped  
through to our controllers and caused ActionView::MissingTemplate  
exceptions. They’re from URLs like

```
/artists/123-radiohead.php

```

I feel like it should be possible to block this request at the routing  
stage - before it reaches the artists controller, but I can’t see how  
it could be done. We use restful routes, so the artists controller is  
wired up using

```
map.resources :artists

```

Is there any way to add an option to this call to specify the formats  
that are acceptable (and thus return a 40x code if the format is not  
in the whitelist?)

e.g.

```
map.resources :artists, :format => [:html, :json]

```

I can’t see anything in the docs, or indeed the code, which would let  
me do this, but I might well have missed something.

cheers,  
Matt

---

<div class="post-metadata">

**Author:** ![mattwynne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecc23a/32.png) [@mattwynne](https://www.ruby-forum.com/u/mattwynne)\
**Post date:** [October 21, 2009, 3:04am UTC](https://www.ruby-forum.com/t/filtering-routes-based-on-format/177588/2 "2009-10-21T03:04:39Z")

</div>

For routing information you could read here:  
[http://api.rubyonrails.org/classes/ActionController/Routing.html](http://api.rubyonrails.org/classes/ActionController/Routing.html)

I’m guessing you could use regular expressions or something else to  
reduce the actions that could be called on a given controller.

Another thing you could do is use method\_missing and redirect to an  
error page, I guess.

Pepe
