Right way to pass conditionals to partials

Hi All,

I have some partials that need to be rendered a bit differently
depending on the context. To make matters worse, sometimes these
partials are including other partials, that I’d like to control from the
main template. These partials are templates that look similar in
different contexts, but have different controls depending on where
they’re being rendered. I tried locals, but the result looks ugly - I
basically have to do this:

<% if !defined?(nocontrols) && !nocontrols ->
html to render controls
<% end ->

Then in my main template I call <% render(:partial => “partial”, :locals
=> { :nocontrols => true }) >

This works, but the convoluted if statements make me cringe. Plus, I’d
have to specifically pass these locals to any nested partials, and that
gets too complicated.

Declaring locals in controllers work, but then I can’t include two
partials with different parameters…

There has to be a better way to do this.

There has to be a better way to do this.

What abt a Helper() ? If nothing else you could consolidate the
convoluted IF statements… Looks like youre tyring to do a role based
exposure of controls , e.g. an admin can see this button, etc. If so it
might be worth considering some kind of container that would have the
html controls [do don’t this in the model tho - bad violation of MVC]
for a given roll - then the view [your .rhtml] can simply render whats
in the container [probably just a plain old ruby object] - the
controller would of course populate the container based on the role of
the current user. This way your view simply renders whats there [which
could mean nothing, if applicable]… this would alleviate the need for
any role-type processing in your partials, i.e. avoid the problem all
together.