Best way to render partial

Hi,

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

[1]
------layouts/application.html.erb--------
...
<div id="content">
  <%= yield %>
</div>
...

-------some_action.html.erb--------
...
<h1>Page title</h1>
<p>Some contents...</p>
...

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

-------some_action.html.erb--------
<div id="content">
...
<h1>Page title</h1>
<p>Some contents...</p>
...
</div>

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

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

Sam,

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

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,

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.

Sam Kong wrote:

Hi,

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

[1]
------layouts/application.html.erb--------
...
<div id="content">
  <%= yield %>
</div>
...

-------some_action.html.erb--------
...
<h1>Page title</h1>
<p>Some contents...</p>
...

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

-------some_action.html.erb--------
<div id="content">
...
<h1>Page title</h1>
<p>Some contents...</p>
...
</div>

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,