[Rails] Re: Encoding
Hi Erica,
I ran into similar situation a while ago for a webservice app I was
working on where I had to handle a lot of bad / untrusted non-utf8
data, and found a fix that met the needs of the app using Iconv
(http://www.ruby-doc.org/stdlib/libdoc/iconv/rdoc/index.html)
following a strategy outlined by Paul Battley (http://po-ru.com/diary/
fixing-invalid-utf-8-in-ruby-revisited/):
...
def AppUtil.force_utf8(str)
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
return ic.iconv("#{str} ")[0..-2]
end
...
Jeff
On Jun 16, 5:27 pm, Erica <ericarhol...@gmail.com> wrote:
> What's a good solution for fixing character encoding problems for
> compatibility between ascii and utf-8? The database is postgres and
> is encoded in utf-8.
>
> Once in awhile there will be a compatibility error from strings from a
> webform.
>
> Is there a command to fix this besides using
> a_string.force_encoding('utf-8')? Even this doesn't seem to always
> work either.
>
> Thanks,
>
> Erica
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home