I usually write helpers that way:
def bloco_vazio (texto = "", btn = "", args={})
titulo = content_tag :h3, "Vazio!"
p = content_tag :p, texto
content_tag :div, (titulo + tag(:hr) + p + btn ), args
end
But i commonly see people using other approaches, like:
def flash_notice
html = ""
unless flash.empty?
flash.each do |f|
html << "<div class='alert alert-#{f[:type].to_s}'>"
html << "<a class='close' data-dismiss='alert'>×</a>"
html << f[:text].to_s
html << "</div>"
end
end
html
end
or
def a_helper (some_text ="")
%{ <h3>some title</h3>
<p>#{some_text}</p>
}%
end
I used these two lasts in the past and ran into some problems then started using the content_tag and tag helpers, even that i still have to use the .html_safe method sometimes.
Is there a standard way to build helpers?
If html is longer than 1 line, i usually put the html in a partial and call it with a custom helper method
view
helper
partial