Forum: Ruby on Rails Resource nested in multiple other resources

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mark C. (Guest)
on 2007-01-24 20:41
(Received via mailing list)
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<><
Zack C. (Guest)
on 2007-01-24 22:37
(Received via mailing list)
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
This topic is locked and can not be replied to.