Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8496327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:49:18+00:00 2026-06-10T23:49:18+00:00

I usually write helpers that way: def bloco_vazio (texto = , btn = ,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:49:20+00:00Added an answer on June 10, 2026 at 11:49 pm

    If html is longer than 1 line, i usually put the html in a partial and call it with a custom helper method

    view

    <= display_my_html(@item, {html_class: "active"}) %>
    

    helper

    def display_my_html(item, opts={})
      name = item.name.upcase
      html_class = opts.key?(:html_class) ? opts[:html_class] : "normal"
    
      render "my_html", name: name, html_class: html_class
    end
    

    partial

    <div class="<%= html_class %>">
      <span class="user">
        <%= name %>
      </span>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to write a state machine in C? I usually
when releasing an instance that could exist or not, I usually write this: if
I usually write (smallish) games in Java using a main 'while' loop somewhat like
I usually write something like this: <mx:VBox height=100% width=155> <mx:Button label=b1 width=100%/> <mx:Buttonlabel=b2 width=100%/>
I usually write python in emacs. I'll often want to re-evaluate my file, which
When I write an SQL statement, I usually write it like this SELECT COUNT(*)
Usually i write my where statements as WHERE key=@0 then add a param. Now
Usually I prefer to write my own solutions for trivial problems because generally plugins
I write a lot of .NET based plug-ins for other programs which are usually
i usually write my code with textmate. a custom command for testing the proj

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.