I need an advice on best practices for DRYing view code. I have three classes (NewsItem, RssItem and BlogItem) in my app, that use separate views, but have similar parts in them. One of the parts is such:
<% if current_user %>
<footer>
<%= marks_bar(@item) %>
<%= favorite_button(@item, "blog_item") || delete_from_favorite_button(@item, "blog_item") %>
<%= share_button(@item) %>
<% if current_user.is_mine?(@item) %>
<div><%= link_to "Edit", edit_user_blog_item_path(current_user, @item) %></div>
<% end %>
</footer>
<% end %>
It's almost equal for all three classes, so I decided to take it out to some separate place. And here I am confused: should I use a partial or helper method for it? I know that helpers are used mostly for separating ruby code from HTML, but in this case the helper will look like:
def toolbar_for(item, type_str, edit_path)
if current_user
content_tag(:footer) do |b|
marks_bar(item).to_s <<
(delete_from_favorite_button(item, type_str) || favorite_button(@item, type_str)).to_s <<
share_button(@item).to_s <<
(content_tag(:div) { link_to("Edit", edit_path)} if current_user.is_mine?(@item)).to_s
end
end
end
So, there is almost no HTML code here.
Could you please give me advice, what method is better in your opinion and why? Also, are there some performance issues in these methods (for example multiple String concatenation or frequent partial loading might be costly)? (This app is rather high-loaded)