rails printer icon helper

written by justin on August 29th, 2008 @ 02:30 PM

I had occasion to need to add a printer icon to some web pages in one of my Rails apps this week. I found a nice free icon at famfamfam.com for the printer. I added the link and javascript and it worked. I decided that it would be a nice idea to make a helper for this so I could easily duplicate it on other pages. Here it is:

# in application_helper.rb
def printer_icon(top=50, left=550)
    "<a href=\"#\" id=\"printer_icon\" style=\"position: absolute; top: #{top}px; left: #{left}px;\" onClick=\"window.print();return false;\">#{image_tag 'printer.png'} </a>"
end

#usage 
<%= printer_icon %>

Works great.

Comments are closed