# Best way to render partial

**URL:** <https://www.ruby-forum.com/t/best-way-to-render-partial/193328>\
**Category:** Rails\
**Created:** [August 16, 2010, 5:08am UTC](https://www.ruby-forum.com/t/best-way-to-render-partial/193328 "2010-08-16T05:08:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [August 16, 2010, 5:08am UTC](https://www.ruby-forum.com/t/best-way-to-render-partial/193328/1 "2010-08-16T05:08:39Z")

</div>

Hi,

I wonder which is better between [1] and [2].

[1]  
------layouts/application.html.erb--------  
…

 \<%= yield %\>
...

-------some\_action.html.erb--------  
…

# Page title

Some contents...

...

[2]  
------layouts/application.html.erb--------  
…  
\<%= yield %\>  
…

-------some\_action.html.erb--------

...
# Page title

Some contents...

...

Practically they are same.  
I think [1] is more DRY.  
But I feel kinda weird with [1] because the wrapper div is separated  
from the real content.

Which do you think is better?

Sam

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [August 16, 2010, 3:23pm UTC](https://www.ruby-forum.com/t/best-way-to-render-partial/193328/2 "2010-08-16T15:23:12Z")

</div>

I prefer [1] as it’s less painful to write the views.

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [August 16, 2010, 4:52pm UTC](https://www.ruby-forum.com/t/best-way-to-render-partial/193328/3 "2010-08-16T16:52:19Z")

</div>

I prefer using [1] when there are lots of views that shares the same  
div#id.  
When there is another which changes the style, I only add a wrapper. If  
there should be another div, I use a content\_for in the views.

Daniel G.  
[http://survey.richapplabs.com/index.php?sid=62661&lang=en](http://survey.richapplabs.com/index.php?sid=62661&lang=en)

2010/8/16 Edmond K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [August 16, 2010, 5:19pm UTC](https://www.ruby-forum.com/t/best-way-to-render-partial/193328/4 "2010-08-16T17:19:44Z")

</div>

Sam K. wrote:

> Hi,
> 
> I wonder which is better between [1] and [2].
> 
> [1]  
> ------layouts/application.html.erb--------  
> …
> 
> \<%= yield %\>
> ...
> 
> -------some\_action.html.erb--------  
> …
> 
> # Page title
> 
> Some contents...
> 
> ...
> 
> [2]  
> ------layouts/application.html.erb--------  
> …  
> \<%= yield %\>  
> …
> 
> -------some\_action.html.erb--------
> 
> ...
> # Page title
> 
> Some contents...
> 
> ...
> 
> Practically they are same.  
> I think [1] is more DRY.  
> But I feel kinda weird with [1] because the wrapper div is separated  
> from the real content.

Option 1 is better. The wrapper div, if it’s constant, _should_ be  
separated from the content – it’s not a part of the content any more  
than a static header or footer would be.

(BTW, I highly recommend Haml instead of ERb.)

> Which do you think is better?
> 
> Sam

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![ssk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@ssk](https://www.ruby-forum.com/u/ssk)\
**Post date:** [August 16, 2010, 4:27pm UTC](https://www.ruby-forum.com/t/best-way-to-render-partial/193328/5 "2010-08-16T16:27:43Z")

</div>

Sam,

> ...

The second one [2] is ideal in situations where your  
layouts/application.html.erb will be used to render different partials  
with  
varied div ids (for whatever reason). Still you can have a “parent div”  
in  
your layout template.

Regards,

* * *

Edmond  
Software Developer | Baobab Health Trust ([http://www.baobabhealth.org/](http://www.baobabhealth.org/))  
|Malawi

Cell: +265 999 465 137 | +265 881 234 717  
Skype: ceekays

Site: [http://sites.google.com/site/ceekaysgroup/](http://sites.google.com/site/ceekaysgroup/) | Blog:  
[http://edceekays.blogspot.com/](http://edceekays.blogspot.com/)  
Facebook: [Redirecting...](http://www.facebook.com/edceekays) | Google profile:  
[http://www.google.com/profiles/kachaleedmond](http://www.google.com/profiles/kachaleedmond)

_“A more radical argument for [statistical Natural Language Processing]  
is  
that human cognition is probabilistic and that language must therefore  
be  
probabilistic too since it is an integral part of cognition.” – Chris  
Manning (1999)_, _Foundations of Statistical Natural Language  
Processing_.

Le 16 aoÃ»t 2010 15:23:12 UTC+2, Fernando P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) a  
Ã©crit :
