Resource nested in multiple other resources


#1

I was wondering how one would approach writing a controller for a
resource that is nested in 2 or more other resources, where the view
and behavior change (albeit slightly) depending on who the parent
resource is.

For example:
/authors/1/books
/publishers/1/books
/owners/1/books

Is there a DRY way to handle this without using a bunch of case
statements?

Would it make much difference if there was a need to access the nested
resource directly as well:
/books

One way that I’ve thought about but haven’t fully fleshed out is using
defining a class BooksController and then define child classes like
AuthorBooksContoller < BooksController and using inheritance to handle
the common methods. How would this work out in the views? Am I
approaching this all wrong?

M<><


#2

On 1/24/07, Mark C. removed_email_address@domain.invalid wrote:

the common methods. How would this work out in the views? Am I
approaching this all wrong?

Mark,

You could have a filter in the books_controller to pick out any
author_id, publisher_id, etc. and scope the Book.find(…) according
to these params. That should be simple and DRY.

Hope this helps.


Zack C.
http://depixelate.com