I’m looking for the DRYest, most conventional, and shortest way to write this helper.
I have something like this at the top of each index view file:
<%= page_header "Blog", "My thoughts on things" %>
And the corresponding helper:
def page_header(title=nil, subtitle=nil)
header = ''
header += content_tag(:h1, title) if title.present?
header += content_tag(:h3, subtitle) if subtitle.present?
return header.html_safe
end
It works, but it’s ugly and I know there is a better way, I just can’t find it.
I’d go for a partial.
app/views/shared/_page_header.html.erb:And the helper would be:
You can also look at cells.