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" />
About this entry
You’re currently reading “Quick and dirty icons in ActionView,” an entry on The If Works
- Published:
- 3.25.08 / 7pm
- Category:
- Metaprogramming, Rails, Ruby
- Tags:
1 Comment
Jump to comment form | comments rss [?] | trackback uri [?]