A nice, simple use of Rails helper methods
Friday, August 15th, 2008I haven’t written many programming-related posts, but lately I’ve been spending a lot of time working on Green Fabric — a new website built with Ruby on Rails. I’ve been learning Rails as I go, and now I’m starting to feel like I really know what I’m doing. So, with that caveat, here’s my first Rails post:
I really like using proper typographical double quotes. I use them in several places on Green Fabric, such as this page, which explains OpenID. Look at the word, register. Here’s how I do that elegantly.
1. My view template has this code:
Most people don't need to <%= quote_this 'register' %> here
2. My application_helper.rb file has this code:
def ldquo '<span class="serif">“</span>' end def rdquo '<span class="serif">”</span>' end def quote_this(html_snippet) return ldquo() + html_snippet + rdquo() end
(In my css file, I’ve defined a “serif” class to set the font-face.) And that’s it!
