DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Ruby Button Helper
I use this for the admin section of my sites. It's good for your basic buttons. I use the tango icon library as well (http://tango.freedesktop.org/Tango_Icon_Gallery).
def button(options = {})
image_source = case options[:type]
when 'edit': "edit-find-replace.png"
when 'preview': "document-print-preview.png"
when 'delete': "edit-delete.png"
else "list-add.png"
end
button = "<img src='/images/icons/#{image_source}' />"
if options[:link]
target = params[:target].blank? ? ">" : " target='#{options[:target]}'>"
"<a href='#{options[:link]}'" + target + button + "</a>"
else
button
end
end
Example usage:
<%= button %> # <img src='/images/icons/list-add.png' />
<%= button :type => "edit", :link => "/edit/5" %>




