scattrbrain
Darshan Patil's personal blog
Masking email in rails
I used to get a lot of spam after I released my blog. I guess most of it was because, I put my email address up on my blog and these spammer spiders got hold of it. I stopped running my mail server for a while ( what was on the site was not my primary email ). This probably got my address of the list. Next I wrote the following snippet of code, and now use it on all my sites. The idea is not new. It masks your email address by using character constants. Your browser recognizes this fine. Most email harvesters do not.
def mask_link(link)
masked_link = ""
link.each_byte do |byte|
masked_link << "&##{byte};"
end
return masked_link
end
def admin_email_link
mailto = "mailto:#{this_site.admin_email}"
"<a href='#{mask_link(mailto)}'>#{mask_link(this_site.admin_email)}</a>"
end
The first routine does the actual text masking. I use the helper method admin_email_link to put my email address on my sites.
Trackbacks
Use the following link to trackback from your own site:
http://scattrbrain.com/articles/trackback/173














