Simple Tooltip with Ruby on Rails

1st Step

add this code in 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

2nd Step

add code in app/views/foo/page.rhtml

3rd Step

add stylesheet in public/stylesheets/yourstyle.css

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

http://rafael.adm.br/p/simple-tooltip-helper-for-ruby-on-rails/

Advertisement
Tagged , , ,

9 thoughts on “Simple Tooltip with Ruby on Rails

  1. Bianca says:

    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?

    Leia mais: http://rafael.adm.br/p/simple-tooltip-helper-for-ruby-on-rails/comment-page-1/#comment-52195#ixzz10jRxqbox

  2. dharmdip says:

    Please use regexp for that

    string.sub(“\n” , ” “)

    if it doesn’t work let me know with your example.

    Thanks.

  3. Bianca says:

    It doesn’t works.
    It looks like this:

    @bla.gsub(“\n” , ” “)},
    :class => ‘tooltip’ %>

  4. Bianca says:

    Sorry, the post cut what I wrote…

    @bla.gsub(“\n” , ” “)},
    :class => ‘tooltip’ %>

  5. Bianca says:

    Again -.-

  6. Bianca says:

    Trying for the last time.

    @bla = “Sentence 1
    Sentence 2
    Sentence 3″

    tooltip “Sentences “,
    { :tooltip => @bla.gsub(“\n” , ” “)},
    :class => ‘tooltip’

  7. Bianca says:

    The result of the “gsub” is just to put spaces…
    But if in my computer it works, in the computer of the others users of the project may not work…

  8. Bianca says:

    Don’t need help anymore, tks.
    Using css.

  9. dharmdip says:

    Hey ! Bianca
    just give me text and let u know solution ..
    thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.