Quick and dirty icons in ActionView

Tiny tiny Rails tip: you can use method_missing to make using icon sets easier when writing Rails views. Behold:

module ApplicationHelper

  def method_missing(sym, *args)
    super unless sym.to_s =~ /_icon$/
    image_tag("silk/#{sym.to_s.gsub(/_icon$/, '')}.png")
  end

end

Now the following call:

<%= pencil_icon %>

produces this image tag:

<img src="/images/silk/pencil.png" />