# Why does no one like render\_component?

**URL:** <https://www.ruby-forum.com/t/why-does-no-one-like-render-component/102153>\
**Category:** Rails\
**Created:** [August 11, 2006, 9:11pm UTC](https://www.ruby-forum.com/t/why-does-no-one-like-render-component/102153 "2006-08-11T21:11:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![blewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@blewis](https://www.ruby-forum.com/u/blewis)\
**Post date:** [August 11, 2006, 9:11pm UTC](https://www.ruby-forum.com/t/why-does-no-one-like-render-component/102153/1 "2006-08-11T21:11:21Z")

</div>

Maybe I’m missing the point?

Lets take for example albums of pictures. If I have a scaffold for  
each, and I’m showing an album, what if I want to list all of the  
pictures that are in the album?

Surely, I’d want to call the List action in the picture controller.  
render\_component would do this perfectly. But we’re told not to use  
render\_component. So instead, I’ll have to put picture list as a  
partial… that means I’ll have to do the sql find for the @pictures in  
the Album controller…?

-Ben L.

---

<div class="post-metadata">

**Author:** ![blewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@blewis](https://www.ruby-forum.com/u/blewis)\
**Post date:** [August 15, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/why-does-no-one-like-render-component/102153/2 "2006-08-15T14:17:53Z")

</div>

Ben L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> Maybe I’m missing the point?

its not people don’t like them, but just don’t use them everywhere  
because  
they are slow. Using render\_component is like making another request.  
using partials is better as they are faster.

> Lets take for example albums of pictures. If I have a scaffold for  
> each, and I’m showing an album, what if I want to list all of the  
> pictures that are in the album?
> 
> Surely, I’d want to call the List action in the picture controller.  
> render\_component would do this perfectly. But we’re told not to use  
> render\_component. So instead, I’ll have to put picture list as a  
> partial… that means I’ll have to do the sql find for the @pictures in  
> the Album controller…?

If you think that your application logic will be cleaner, and you can  
reuse  
them at multiple places, even from outside the application, then use a  
render\_component.

## Cheers,

Surendra S.  
[http://ssinghi.kreeti.com](http://ssinghi.kreeti.com), [http://www.kreeti.com](http://www.kreeti.com)  
Read my blog at: [http://cuttingtheredtape.blogspot.com/](http://cuttingtheredtape.blogspot.com/)  
,----  
| Great wits are sure to madness near allied,  
| And thin partitions do their bounds divide.  
|  
| (John Dryden, Absalom and Achitophel, 1681)  
`----

---

<div class="post-metadata">

**Author:** ![blewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@blewis](https://www.ruby-forum.com/u/blewis)\
**Post date:** [August 16, 2006, 11:40pm UTC](https://www.ruby-forum.com/t/why-does-no-one-like-render-component/102153/3 "2006-08-16T23:40:05Z")

</div>

Hi,

```
I have a acts_as_tree model but I'm not able to create the first 

```

item without a parent.

With this model:

```
class Node < ActiveRecord::Base
	acts_as_tree
end

```

I run:  
n = Node.new  
n.name = ‘my node’  
n.save

I get this error

```
ActiveRecord::RecordNotFound: Couldn't find Subsystem without an ID
    from 

```

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/ac…

Please, my head is burning… I thought it was a database problem with  
fks, I removed them but it persists.

Somebody help me!

TIA  
Romeu Fonseca

–  
No virus found in this outgoing message.  
Checked by AVG Free Edition.  
Version: 7.1.405 / Virus Database: 268.10.10/419 - Release Date:  
15/8/2006

---

<div class="post-metadata">

**Author:** ![blewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@blewis](https://www.ruby-forum.com/u/blewis)\
**Post date:** [August 15, 2006, 2:19pm UTC](https://www.ruby-forum.com/t/why-does-no-one-like-render-component/102153/4 "2006-08-15T14:19:50Z")

</div>

> Surely, I’d want to call the List action in the picture controller.  
> render\_component would do this perfectly. But we’re told not to use  
> render\_component. So instead, I’ll have to put picture list as a  
> partial… that means I’ll have to do the sql find for the @pictures in  
> the Album controller…?
> 
> -Ben L.

Ben:

Actually, if an Album has\_many photos, then it’s a matter of doing this  
in  
your controller:

def list  
@album = Album.find(params[:id], :include=\>[:photos]  
@photos = @album.photos  
end

This gets you the album AND its photos in one database call.

Then in your view, you render the partial

\<%=render :partial =\>"/shared/photos" %\>

Partials are definitely the way to go for most of this stuff. I had  
component rendering going on in one of my earlier projects and I started  
noticing some pretty nasty performance problems. I refactored several of  
those into partials, and others I left in, but I made sure to use  
fragment  
and action caching wherever I could to improve performance.

---

<div class="post-metadata">

**Author:** ![blewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@blewis](https://www.ruby-forum.com/u/blewis)\
**Post date:** [August 17, 2006, 3:05pm UTC](https://www.ruby-forum.com/t/why-does-no-one-like-render-component/102153/5 "2006-08-17T15:05:17Z")

</div>

Somebody please!!!

-----Mensagem original-----  
De: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] Em nome de Romeu Henrique  
Capparelli F.  
Enviada em: quarta-feira, 16 de agosto de 2006 17:36  
Para: removed\_email\_address@domain.invalid  
Assunto: [Rails] acts\_as\_tree: creating the first element

Hi,

```
I have a acts_as_tree model but I'm not able to create the first 

```

item without a parent.

With this model:

```
class Node < ActiveRecord::Base
	acts_as_tree
end

```

I run:  
n = Node.new  
n.name = ‘my node’  
n.save

I get this error

```
ActiveRecord::RecordNotFound: Couldn't find Subsystem without an ID
    from 

```

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/ac…

Please, my head is burning… I thought it was a database problem with  
fks, I removed them but it persists.

Somebody help me!

TIA  
Romeu Fonseca

–  
No virus found in this outgoing message.  
Checked by AVG Free Edition.  
Version: 7.1.405 / Virus Database: 268.10.10/419 - Release Date:  
15/8/2006

* * *

Rails mailing list  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
No virus found in this incoming message.  
Checked by AVG Free Edition.  
Version: 7.1.405 / Virus Database: 268.10.10/419 - Release Date:  
15/8/2006

–  
No virus found in this outgoing message.  
Checked by AVG Free Edition.  
Version: 7.1.405 / Virus Database: 268.11.1/421 - Release Date:  
16/8/2006

---

<div class="post-metadata">

**Author:** ![blewis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@blewis](https://www.ruby-forum.com/u/blewis)\
**Post date:** [August 17, 2006, 7:17pm UTC](https://www.ruby-forum.com/t/why-does-no-one-like-render-component/102153/6 "2006-08-17T19:17:50Z")

</div>

On Aug 16, 2006, at 3:35 PM, Romeu Henrique Capparelli F. wrote:

> ActiveRecord::RecordNotFound: Couldn’t find Subsystem without an ID  
> from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/  
> ac…

this looks like a db schema error – check that you have appropriate  
primary and foreign keys, and if that fails, post your schema?

-faisal
