Over a million developers have joined DZone.

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 = ""
    
    if options[:link]
      target = params[:target].blank? ? ">" : " target='#{options[:target]}'>"
      ""
    else
      button
    end
  end


Example usage:

<%= button %>
# 



<%= button :type => "edit", :link => "/edit/5" %>
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}