# Replacing render\_component

**URL:** <https://www.ruby-forum.com/t/replacing-render-component/173023>\
**Category:** Rails\
**Created:** [July 31, 2009, 2:30pm UTC](https://www.ruby-forum.com/t/replacing-render-component/173023 "2009-07-31T14:30:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Cugley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Michael\_Cugley](https://www.ruby-forum.com/u/Michael_Cugley)\
**Post date:** [July 31, 2009, 2:30pm UTC](https://www.ruby-forum.com/t/replacing-render-component/173023/1 "2009-07-31T14:30:39Z")

</div>

New to Ruby, new to Rails. I’ve googled much on this topic, but I don’t  
think I have enough knowledge to form the correct queries.

I’ve been given the task of resurrecting an old Rails app that’s not  
seen the light of day for two years. It seems to rely heavily on  
render\_component which I am given to understand by various error  
messages is now deprecated, unfashionable, and unfit to be seen with on  
social occasions.

However, what I haven’t found is much on what to do with  
render\_component code to make it more modern, apart from “Components are  
a special-purpose approach that can often be replaced with better use of  
partials and filters.” Whatever they may be.

Is there anywhere I can go to help me understand what the  
render\_component calls are doing in this particular instance, and how  
best to refactor them?

–  
Mike Cugley  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Michael\_Cugley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Michael\_Cugley](https://www.ruby-forum.com/u/Michael_Cugley)\
**Post date:** [July 31, 2009, 3:43pm UTC](https://www.ruby-forum.com/t/replacing-render-component/173023/2 "2009-07-31T15:43:50Z")

</div>

The render\_component was extracted as a plugin, so the documentation  
here should explain what render\_component is actually doing:

> **[GitHub - rails/render\_component: NOTICE: official repository moved to...](https://github.com/rails/render_component/tree/master)**
>
> master

I have provided an example here of a refactoring based on what you  
described below:

> <https://gist.github.com/nicholasjhenry/159227>

HTH,  
Nicholas

---

<div class="post-metadata">

**Author:** ![Michael\_Cugley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Michael\_Cugley](https://www.ruby-forum.com/u/Michael_Cugley)\
**Post date:** [July 31, 2009, 5:08pm UTC](https://www.ruby-forum.com/t/replacing-render-component/173023/3 "2009-07-31T17:08:41Z")

</div>

Nicholas H. wrote:

> HTH,  
> Nicholas

I’ve had a go at installing the plugin (just to get the thing to work  
enough I can see what it does) but that just threw up other errors;  
however, I think the idea of looking through the docs and code is a good  
one.

The refactoring looks interesting - I’ll see if I can wrap my newbie  
head around it 🙂

Thanks.

–  
Mike Cugley  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Michael\_Cugley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Michael\_Cugley](https://www.ruby-forum.com/u/Michael_Cugley)\
**Post date:** [July 31, 2009, 10:32pm UTC](https://www.ruby-forum.com/t/replacing-render-component/173023/4 "2009-07-31T22:32:57Z")

</div>

I had to do this with my first few rails apps after it turned out that  
render\_component had horrible performance. It was kind of a pain  
because the first rails books used them in examples and there was no  
discussion back then about whether or not it was a good idea.  
Anyway…

From my experience a render component in a view should be replaced by  
a render :partial and a render component in a controller could be  
replaced by a filter of some sort. That said, it has been a long long  
time and I might be a bit off there. At anyrate, I had only really  
used them in views and converting them usually involved just making  
sure whatever variables they depended on were passed in as locals or  
already available as instance variables.

Some specific code examples could allow use to make suggestions about  
how to start re-factoring.

---

<div class="post-metadata">

**Author:** ![Michael\_Cugley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@Michael\_Cugley](https://www.ruby-forum.com/u/Michael_Cugley)\
**Post date:** [July 31, 2009, 5:19pm UTC](https://www.ruby-forum.com/t/replacing-render-component/173023/5 "2009-07-31T17:19:48Z")

</div>

Yeah, I wouldn’t be surprised if the plugin is not compatible with the  
latest versions of rails. It probably isn’t being maintained. If you  
like the concept of components, you can check out Cells which is an  
improved version of rendered\_component:

> **[GitHub - trailblazer/cells: View components for Ruby and Rails.](https://github.com/trailblazer/cells/tree/master)**
>
> master

This is an improved version of the concept. I haven’t tried it out  
myself, but have been meaning to.

Cheers,  
Nicholas
