# STI and routing

**URL:** <https://www.ruby-forum.com/t/sti-and-routing/155748>\
**Category:** Rails\
**Created:** [December 16, 2008, 10:28am UTC](https://www.ruby-forum.com/t/sti-and-routing/155748 "2008-12-16T10:28:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![coxy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coxy](https://www.ruby-forum.com/u/coxy)\
**Post date:** [December 16, 2008, 10:28am UTC](https://www.ruby-forum.com/t/sti-and-routing/155748/1 "2008-12-16T10:28:59Z")

</div>

Hello all,

I have a main model Article, which is subclassed by several others  
like so:

* * *

## class Music \< Article class RecordReview \< Music; end class Interview \< Music; end end class Film \< Article class Review \< Film; end class Interview \< Film; end end …etc

Doing it this way I can simply call Music.all, or  
Music::RecordReview.all etc to find relevant articles. For simplicity  
I’ve decided to use only one controller ArticlesController. My URL  
schema is like this:

* * *

## ‘/music’ ‘/music/record\_reviews’ ‘/music/record\_reviews/1’ ‘/music/record\_reviews/new’ ‘/music/record\_reviews/1/edit’ ‘/film’ ‘/film/reviews’ …etc

So - my question is - does anybody know a clean way to define this in  
routes.rb, bearing in mind that all requests need to be passed to the  
ArticlesController, which then needs to determine which type of  
article we’re currently requesting.

Right now i’m just doing something like this:

* * *

## map.connect ‘:section/:subsection/:id’, :controller =\> ‘articles’, :action =\> ‘show’ …etc

and then I use a before\_filter to determine the type from the :section  
and :subsection params - which works - but I then don’t get any of the  
url/path helpers generated doing a map.resources so things are getting  
a bit messy.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![coxy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coxy](https://www.ruby-forum.com/u/coxy)\
**Post date:** [December 16, 2008, 7:02pm UTC](https://www.ruby-forum.com/t/sti-and-routing/155748/2 "2008-12-16T19:02:27Z")

</div>

If you name the route you would…

like:  
map.music ‘:section/:subsection/:id’, :controller =\>music’, :action  
=\> ‘show’

then you could use  
music\_url  
(:action=\>‘whatever’, :section=\>‘section’, :subsection=\>‘subsection’,  
:id=\>1)

---

<div class="post-metadata">

**Author:** ![coxy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coxy](https://www.ruby-forum.com/u/coxy)\
**Post date:** [December 16, 2008, 9:31pm UTC](https://www.ruby-forum.com/t/sti-and-routing/155748/3 "2008-12-16T21:31:02Z")

</div>

Thanks Wally. Think this could work…
