STI and routing

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
class Film < Article
class Review < Film; end
class Interview < Film; end

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:


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’

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

If you name the route you would…

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

then you could use
(:action=>‘whatever’, :section=>‘section’, :subsection=>‘subsection’,

Thanks Wally. Think this could work…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs