# Render :partial =\> :url - is it possible?

**URL:** <https://www.ruby-forum.com/t/render-partial-url-is-it-possible/107441>\
**Category:** Rails\
**Created:** [June 21, 2007, 9:30pm UTC](https://www.ruby-forum.com/t/render-partial-url-is-it-possible/107441 "2007-06-21T21:30:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_McGuigan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/958977/32.png) [@James\_McGuigan](https://www.ruby-forum.com/u/James_McGuigan)\
**Post date:** [June 21, 2007, 9:30pm UTC](https://www.ruby-forum.com/t/render-partial-url-is-it-possible/107441/1 "2007-06-21T21:30:30Z")

</div>

Hi, this is my first post to the list. I’m still learning the rails  
framework, having done most of my previous web development in PHP. I’ve  
done a bit of googling for the answer to this question, but maybe I’m  
just lacking the right word to search for.

Several parts of my site, such as sidebar components, are  
self-contained, modularized and re-used in several parts of the site.  
The sidebar is part of the layout (I’m using the nested\_layout plugin),  
rather than the page view.

# /app/layouts/layout\_3\_col.rhtml

\<%= render :partial =\> @col\_left\_partial || 'col\_left' %\>

However this means I need to generate the data for the sidebar  
components within each model, and not more-cleanly in a separate model  
for the sidebar component itself.

What I am after is a system where I could create a separate model, view  
and controller for each sidebar component and then call render :url =\>  
/sidebars/left\_col/3

I’m assuming a similar approach would be used in AJAX, where you replace  
a DIV with a HTML fragment generated on the server, but would want to  
show the fragment as part of the original page without generating a  
series of AJAX requests on page load.

Is this possible in rails, whats the technique called (so I can google  
for it) or am I going about it the wrong way.

Thanks in advance.

–  
James

---

<div class="post-metadata">

**Author:** ![James\_McGuigan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/958977/32.png) [@James\_McGuigan](https://www.ruby-forum.com/u/James_McGuigan)\
**Post date:** [June 21, 2007, 10:01pm UTC](https://www.ruby-forum.com/t/render-partial-url-is-it-possible/107441/2 "2007-06-21T22:01:35Z")

</div>

> # /app/layouts/layout\_3\_col.rhtml
> 
> and controller for each sidebar component and then call render :url =\>  
> /sidebars/left\_col/3

What you are looking for is in fact called “components” which are going  
out of style (if they aren’t already) as they are inefficient.

If you have a sidebar that is shared among many areas of the site, yet  
is  
totally self contained, I would simply break MVC a little bit and make a  
“MySideBarModel.find…” call followed by the rendering code to display  
it.

Yes, it breaks MVC, but it’s a much simpler in a lot of ways.

Or if it’s really shared _everywhere_ create a before\_filter in your  
application.rb that loads up the data needed for every request.

-philip
