views:

242

answers:

2

This might be a tough one

I have a site which is using a polymorphic comments model.

Lets say the first model is library, and the second is book

so we have, library/1/book/63/

how do I route it so comments are then library/1/book/63/comments/1 ?

Thanks,

Elliot

update: looking for code for routes.rb file

A: 
map.resources :libraries do |library|
    library.resources :books, :has_many=>[:comments]
end
ez
A: 

You just nest them:

map.resources :libraries do |library|
    library.resources :books do |book|
       book.resources :comments
    end
end

It may be confusing, but the polymorphic aspect of the data model is independent of the routes.

To call them via named routes, for a comment you'll need to provide a library and a book, even if it's unambiguous.

ndp