Forum: Ruby on Rails Characterset conversion

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
onno.van.der.straaten (Guest)
on 2005-11-23 10:32
(Received via mailing list)
Hi group,
I have a simple web-app that reads files and stores them in MySQL. Now I
noticed that some characters are converted so some characterset
conversion must be taking place. For example the character - is
converted in รข??.

From phpinfo:
HTTP_ACCEPT_CHARSET = ISO-8859-1,utf-8;q=0.7,*;q=0.7
HTTP Headers Information = Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7

I have tried adding the following to my virtualhost: AddDefaultCharset
utf-8
But that did not help. I suspect the problem is not the webserver-config
as the web-app is just reading a file from the local filesystem and
storing it in mysql. Maybe this is caused by my windows settings?

The MySQL table column is of type longtext and utf8 characterset, the
same as the html documents.

I'm using ruby 182-15.

Any ideas on how to fix this will be greatly appreciated.
Onno






This e-mail and any attachment is for authorised use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by, any other party. If you are
not an intended recipient then please promptly delete this e-mail and
any attachment and all copies and inform the sender. Thank you.
jonte (Guest)
on 2005-11-23 10:57
(Received via mailing list)
Straaten, Onno van der wrote:
> The MySQL table column is of type longtext and utf8 characterset, the same as the html 
documents.
>
> This e-mail and any attachment is for authorised use by the intended recipient(s) only. 
It may contain proprietary material, confidential information and/or be subject to legal 
privilege. It should not be copied, disclosed to, retained or used by, any other party. If 
you are not an intended recipient then please promptly delete this e-mail and any 
attachment and all copies and inform the sender. Thank you.
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
You could try something like I do in my AJAX UTF-8 to ANSI
convertion....
<code>

require 'iconv'

def auto_complete_for_movie_movie_id
da_title = Iconv.new('iso-8859-15',
'utf-8').iconv(params[:movie][:movie_id])
auto_complete_responder_for_movies da_title
end

</code>
(I know it looks strange to have movie_id as a "movie title" and not the
id from the DB, but I must handle Titles that do not yet exists)

In your case:
safe_text = Iconv.new( 'utf-8','iso-8859-1',).iconv(some_text_from_file)

More on "iconv" on http://wiki.rubyonrails.com/rails/pages/iconv

Regards
Jonas Montonen,
------------------------
http://bytadvd.se - DVD Swapping site in Swedish
This topic is locked and can not be replied to.