I'm looking for a helper that changes link_to behaviour if the file is a PDF, i.e. displays a tooltip.
How can I write a helper that overrides link_to only if the file is a pdf?
I'm looking for a helper that changes link_to behaviour if the file is a PDF, i.e. displays a tooltip.
How can I write a helper that overrides link_to only if the file is a pdf?
Why do you want to change the behavior of link_to
? For tooltips you need to set the title
attribute or you use something with javascript. So you don't need to change the default behavior.
<%= link_to "A PDF document",
"/some_file.pdf",
:title => "Tooltip in Most Browsers"
#, :class => "pdf %>
If you want some fancy cool tooltip try google "jQuery tootltip" or something similar.
your could also add :class => "pdf"
, to be able to find all pdf links with javascript. In jQuery it could look like this:
$('a.pdf');
If you make a lot of links like this you can DRY it up with this helper:
def link_to_pdf(name,path,title)
link_to name, path, :title => title, :class => "pdf"
end