DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

Ruby Button Helper

Snippets Manager user avatar by
Snippets Manager
·
Sep. 24, 08 · · Code Snippet
Like (0)
Save
Tweet
440 Views

Join the DZone community and get the full member experience.

Join For Free
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" %>

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Configure Git in Eclipse IDE
  • Role of Development Team in an Agile Environment
  • The Most Popular Kubernetes Alternatives and Competitors
  • 5 Steps to Strengthen API Security

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo