# Best way to create a route that only accepts one format

**URL:** <https://www.ruby-forum.com/t/best-way-to-create-a-route-that-only-accepts-one-format/156420>\
**Category:** Rails\
**Created:** [December 27, 2008, 4:34am UTC](https://www.ruby-forum.com/t/best-way-to-create-a-route-that-only-accepts-one-format/156420 "2008-12-27T04:34:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshua-asem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshua-asem](https://www.ruby-forum.com/u/joshua-asem)\
**Post date:** [December 27, 2008, 4:34am UTC](https://www.ruby-forum.com/t/best-way-to-create-a-route-that-only-accepts-one-format/156420/1 "2008-12-27T04:34:38Z")

</div>

Hey guys,

I haven’t done this before so I thought I’d ping the mailing list to see  
if anyone has any better ideas than what I’ve come up with.

I want to create a route that looks something like this:

[url.com/counter/:id.png](http://url.com/counter/:id.png)

Basically, this will route to the “show” method in the controller, and  
should only work if the format requested is .png.

I’m using this controller for other things as well, but any other time  
it’s accessed through a nested route:

[url.com/users/1/ads/:id](http://url.com/users/1/ads/:id)

So here’s what I’ve come up with:

map.resources :ads, :only =\> :show, :as =\> :counter, :requirements =\>  
{ :format =\> :png }  
map.resources :users, :has\_many =\> :ads

This seems to be working, however instead of a 404 Not Found being  
returned to the browser, it’s returning a 406 Not Acceptable.

Is there any way to generate this route so that unless the format is png  
it will return the usual 404 Not Found when a route doesn’t exist?

Thanks,  
Josh
