Restful resources with a somewhat complex scheme


#1

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 :slight_smile:

TIA,
ngw