For the sake of simplicity, let's say I have something like
<div class='important_class'>
<%= @model.attribute %>
</div>
Imagine the important_class
div was actually a large hierarchy of divs, and there was like 7 closing tags. And now imagine I have 5 views that have the exact same look, besides the content in the center, where I might have @model1.attribute
, model2.attribute
and so on. What's the best way of using partials in this case?
Proposed solution 1
Make 2 partials called _top_part.html.erb
and _bottom_part.html.erb
that contains the top part and bottom parts, and then use them in different views. And the code would look like
<%= render 'top_part' %>
<%= @model.attribute %>
<%= render 'bottom_part' %>
Proposed solution 2
In the controller level, pass a variable into the view to determine which partial to render, it will look something like
<div class='important_class'>
<%= render @place+'_partial' %>
</div>
The reason why I don't like solution 2 is because the @place is too tightly coupled with the partials, and you might get weird behaviour with rendering the same view from many different controllers.
Suggestions?