# Components going out of style?

**URL:** <https://www.ruby-forum.com/t/components-going-out-of-style/61506>\
**Category:** Rails\
**Created:** [May 24, 2006, 5:28pm UTC](https://www.ruby-forum.com/t/components-going-out-of-style/61506 "2006-05-24T17:28:53Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![nola](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@nola](https://www.ruby-forum.com/u/nola)\
**Post date:** [September 2, 2006, 8:22pm UTC](https://www.ruby-forum.com/t/components-going-out-of-style/61506/21 "2006-09-02T20:22:55Z")

</div>

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.

–  
- Adam

\*\* Expert Technical Project and Business Management  
\*\*\*\* System Performance Analysis and Architecture  
\*\*\*\*\*\* [[http://www.adamfields.com](http://www.adamfields.com) ]

[[http://www.aquick.org/blog](http://www.aquick.org/blog) ] … Blog  
[[Adam Fields Resume](http://www.adamfields.com/resume.html) ]… Experience  
[[Adam Fields | Flickr](http://www.flickr.com/photos/fields) ] … Photos  
[[http://www.aquicki.com/wiki](http://www.aquicki.com/wiki) ]…Wiki

---

<div class="post-metadata">

**Author:** ![nola](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@nola](https://www.ruby-forum.com/u/nola)\
**Post date:** [April 27, 2007, 7:56pm UTC](https://www.ruby-forum.com/t/components-going-out-of-style/61506/22 "2007-04-27T19:56:44Z")

</div>

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  
the partial.

> **[ActionController::Base](https://api.rubyonrails.org/classes/ActionController/Base.html#M000267)**
>
> Action Controllers are the core of a web request in Rails. They are made up of one or more actions that are executed on request and then either it renders a template or redirects to another action.

b

---

<div class="post-metadata">

**Author:** ![nola](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/eb9ed0/32.png) [@nola](https://www.ruby-forum.com/u/nola)\
**Post date:** [April 27, 2007, 3:58pm UTC](https://www.ruby-forum.com/t/components-going-out-of-style/61506/23 "2007-04-27T15:58:31Z")

</div>

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)) %\>

blablabla
\<% end %\>

I prefer to keep the view clueless about the model relationships and  
write something like that instead :

\<% if(@display\_some\_section) %\>

blablabla
\<% 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(…)) ?

[Previous page](https://www.ruby-forum.com/t/components-going-out-of-style/61506.md?page=1)
