I usually write helpers:
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 usually see people using other approaches, for example:
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 last two in the past and ran into some problems, and then started using the helpers content_tag and tag, even if I sometimes have to use the .html_safe method.
Is there a standard way to create helpers?
source share