Brasil

02 julho 2006 ~ 5 Comentários, deixe o seu »

Simple tooltip helper for Ruby on Rails

A simple tooltip helper with span tag and title attrbute for Ruby on Rails framework.

app/helpers/application_helper.rb

def tooltip(content, options = {}, html_options = {}, *parameters_for_method_reference)
html_options[:title] = options[:tooltip]
html_options[:class] = html_options[:class] || ‘tooltip’
content_tag("span", content, html_options)
end

app/views/foo/bar.rhtml

< %= tooltip "Tags", { :tooltip => ’some keywords to categorize your data and help in future searches’ }, :class => ‘mytooltip’ %>

public/stylesheets/yourstyle.css

.mytooltip {
cursor: help;
color: green;
border-bottom: 1px dotted green
}

5 Respostas para “Simple tooltip helper for Ruby on Rails”

  1. Joram Barrez 1 março 2007 at 12:56 PM Permalink

    Thans for this helpful bit of code! I was searching a few hours already to do the same!

  2. Zeba 29 outubro 2008 at 5:27 AM Permalink

    Thanx a lot………….it was very usefull…!

  3. Bianca 27 setembro 2010 at 10:20 AM Permalink

    And what should I do to separate the sentence to be shown in many lines?
    Te “\n” command and the “*13″ command doesn’t works.

    My text of the tooltip is really big, but it isn’t a text itself… It is multiple sentences, witch I want to show each one in one line.

    What can I do?

  4. Rafael Lima 25 outubro 2010 at 9:56 PM Permalink

    Bianca,

    The answer is: nothing.

    It’s quite simple, so you can’t have multiple lines. It is a browser limitation.