Rails 3 encode non ascii?
I'm wondering if there's a helper in rails 3 or a simple way of converting all non ascii characters to their htm开发者_如何转开发l entities. Such as: à to à. ® to ®
The purpose of this is to replace any such characters before exporting to a CSV format. Since viewing the characters in Excel doesn't turn out too well. Worst case scenario I'll just use gsub for each instance, but I'd rather avoid that if possible.
If you can't find anything for Rails then you could check out HTMLEntities
:
http://htmlentities.rubyforge.org/
require 'htmlentities'
coder = HTMLEntities.new
string = "<élan>"
coder.encode(string, :named) # => "<élan>"
精彩评论