How to protect my e-mail address from spambots

梦想的初衷 提交于 2019-12-06 06:57:40

Just use the built in mail_to helper that Rails has...

http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-mail_to

mail_to 'email@here.com', 'click to email', :encode => .... # couple of encoding options

NOTE: This does not work in Rails 4 anymore. From the docs: Prior to Rails 4.0, mail_to provided options for encoding the address in order to hinder email harvesters. To take advantage of these options, install the actionview-encoded_mail_to gem. (Thanks to @zwippie)

rubo77

You could simply replace the @-sign as a simple solution:

"example@example.com".sub("@","-at-") #=> example-at-example.com
"example@example.org".sub("@","{at}") #=> example{at}example.org

see obfuscate emails with ruby to protect against harvesters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!