[LRUG] Rails Question : Matching Share Nested Resources to Controllers

Tom Stuart tom at experthuman.com
Mon Nov 5 06:29:08 PST 2007


On 5 Nov 2007, at 14:12, Anthony Green wrote:
> What approach would you take here ?
> Contextual checking in the views ?
> or partial names based on parent resource instance variable name ?
> Or some other way ?

It depends how much of the view needs to change. Of course you could  
go the whole hog and "render :template" an entire custom page  
depending on the parent object, or be more gentle about it and have a  
single template which uses helpers to render the appropriate partials  
at the right points in the page.

The actual mechanism for checking and enforcing the context is up to  
you, but there are probably a few tidy ways of doing it. Given that  
multiple partials might be involved, it could get difficult to name  
the partials themselves after the parent resource's "instance variable  
name" (i.e. class), but there's no reason you couldn't have matching  
collections of partials in e.g. the views/authors and views/publishers  
directories, and form the paths to the partials by interpolating the  
class name of the parent into a larger string (provided a parent is  
present).

But aside from this I agree with Craig Webster's second message on  
this thread re: how much view context should really change between  
these different scenarios. In each case the user's conceptually doing  
the same thing (albeit with different filters) and it would be unusual  
for things to be radically different between views. In many cases it  
comes down to just showing some representation of the parent object  
itself (which might include e.g. breadcrumbing, calling #name on it  
etc) which shouldn't be onerous enough to warrant completely separate  
controllers.

Cheers,
-Tom



More information about the Chat mailing list