On Apr 27, 2006, at 02:12 PM, PJ Hyett wrote:
Has anyone done some benchmarking? I’d like to use partials if I
could, but not if they’re slower.
I’ve been seeing questions similar to this over the past couple of
weeks and I have to say that I’m a bit confused by them. At what
point did people start thinking partial page templates were somehow
in competition with view helper methods?
Partials are how you handle chunks of repetitive HTML in your views.
They are rendered through eRb and designed to fit seamlessly in your
page templates. I won’t go into the benefits of
“render :partial… :collection” here. Suffice it to say, if you are
putting looping code into your page templates, just stop it, now.
You’ll thank me later.
View helper methods are a way to take a particular bit of complex,
usually conditional, view logic and move it out of your eRb code,
replacing it with a single method call. While you can use it to
construct several lines of eRb code, doing so simply makes no sense
to me. Where I tend to use helpers is when I’ve got a form control,
usually a button, that only needs to display (or display in a certain
way) based on the logged in user, or some other programmatic setting.
I almost never use a helper to return more than a single page
element, mostly because that’s what seems to make the most sense to me.
Helper methods are designed to work, in cooperation, with your view
templates. All your view templates. Including your partials. There’s
no competition here and, I would argue, no overlap in functionality…