On Sat, Sep 02, 2006 at 05:34:08PM -0000, DHH wrote:
Currently, I believe components just have some performance issues. I’d
encourage you to benchmark with and without to see whether it matters
in your case. And then be on the lookout for other/better ideas that we
could possibly do this. As well as keeping in mind that components are
not a general strategy for compartmentalizing things in Rails, unless
they have this portlet-type flavor we’re discussing.
Components have had performance issues in EVERY web platform I’ve
used, but usually that’s related to the overhead of an additional
request/ssi, instantiating the execution stack, or something related.
I suspect (but haven’t dug into the code to confirm) that the right
way to approach this might be to stick a continuation somewhere in the
rendering path to save all of that setup and use it later to execute
an additional action/view pair.
** Expert Technical Project and Business Management
**** System Performance Analysis and Architecture
****** [ http://www.adamfields.com ]
[ http://www.aquick.org/blog ] … Blog
[ http://www.adamfields.com/resume.html ]… Experience
[ http://www.flickr.com/photos/fields ] … Photos
[ http://www.aquicki.com/wiki ]…Wiki
You can pass vars to a partial using a render option called :locals
which points to a hash of names/values to be available as local vars in
I understand why partials should be used instead of components, but how
can you set clever instance variables that will be used by the partial?
The thing is, I prefer not putting business logic into RHTML
Basically, instead of writing the following in a view :
<% if(@product.categories.includes?(some_category)) %>
<% end %>
I prefer to keep the view clueless about the model relationships and
write something like that instead :
<% if(@display_some_section) %>
<% end %>
With components, you can execute logic and create any instance variables
you need before the view gets rendered. That’s what I liked about them.
Is there a way to do the same with partials?
By the way, what’s your take about writing code like
“if(@product.categories.includes?(some_category))” in a view? Do you
think it is bad design or is it ok as long as you don’t access the model
directly (Product.find(…)) ?