On 1/24/07, Mark Carey <lists-MMYp1bZq/KasTnJN9+BGXg@public.gmane.org>
wrote:>
> 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?
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 Chandler
http://depixelate.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---