# Restful resources with a somewhat complex scheme

**URL:** <https://www.ruby-forum.com/t/restful-resources-with-a-somewhat-complex-scheme/163805>\
**Category:** Rails\
**Created:** [March 25, 2009, 2:31am UTC](https://www.ruby-forum.com/t/restful-resources-with-a-somewhat-complex-scheme/163805 "2009-03-25T02:31:17Z")\
**Posts on this page:** 1\
**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:** [March 25, 2009, 2:31am UTC](https://www.ruby-forum.com/t/restful-resources-with-a-somewhat-complex-scheme/163805/1 "2009-03-25T02:31:17Z")

</div>

Hi guys, I’m trying to figure out the routing of my application but  
unfortunately I’m having some problems.

I have a polymorphic association where ads are related to 5 different  
kinds of resources (videos, prints, radios, banners and concepts),  
where every :ad has\_one :resource.  
Ads belong\_to and can be filtered by contest, the contest object has a  
permalink.

This is the routing scheme I came up with:

ads/index =\> collection of all ads  
ads/contest\_permalink =\> collection of all ads of a contest  
ads/videos =\> collection of all videos  
ads/contest\_permalink/videos =\> collection of all videos of a specific  
contest  
ads/contest\_permalink/videos/ads\_permalink =\> specific ad

The reason behind this choice is that contest permalink normally is  
the name of a famous company, and ad permalinks are a common SEO  
practice (both things are very good SEO wise).  
This way a specific ad is going to be something like  
ads/nike/videos/foobar where nike is the contest permalink, and foobar  
is the ad permalink. Both permalinks are of course unique keys.

This design satisfies me, it’s both restful and the urls are clear  
enough to be guessable.

My problem and my question is about the implementation. If I had to  
implement it following the data scheme it would be something like  
map.resources :ads, :has\_one =\> [:video, :print, …] but of course  
this won’t do the trick: I should overwrite Ad.to\_param to reproduce  
the contest permalink which is not unique inside the ads scope (of  
course), and the resource is without id (and AFAIK we just have  
settable url prefixes, I can’t append something like a permalink).  
Is there a way that let’s me use a generic string filter on the ads  
resource and still have the specific ad type (say, Video) have a  
to\_param that maps on the permalink ?  
I know that I can still have named routes, but I would really like to  
have all the goodness that comes with map.resources.  
I believe that this is a decent restful architecture (but I’m happy if  
someone comes up with a better solution), I find it kind of weird that  
rails asks me to define everything by hand - but maybe I’m asking the  
framework too much 🙂

TIA,  
ngw
