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
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
}
cursor: help;
color: green;
border-bottom: 1px dotted green
}








Thans for this helpful bit of code! I was searching a few hours already to do the same!
Thanx a lot………….it was very usefull…!
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?
Bianca,
The answer is: nothing.
It’s quite simple, so you can’t have multiple lines. It is a browser limitation.