forgot to say: a workaround that works for me is to add the method
“.force_encoding(‘utf-8’)” to any variable with date from my database
eg.:
student.name.force_encoding(‘utf-8’)
Good Night for now
S.
forgot to say: a workaround that works for me is to add the method
“.force_encoding(‘utf-8’)” to any variable with date from my database
eg.:
student.name.force_encoding(‘utf-8’)
Good Night for now
S.
Oh what I forgot. The icompati… error is showing on a line where I’m
using I18n.t and it would return a string with a umlaut.
Gudleik R. wrote:
I’ve been struggling with the same issue a few times, and the solution
that worked for me was to use a different mysql driver: ruby-mysqlin config/environment.rb:
config.gem ‘ruby-mysql’
or in Gemfile:
gem ‘ruby-mysql’
The encoding must also be set in config/database.yml:
adapter: mysql
encoding: utf8
Still not good night …
I tried with rails 3 (rc) and this adapter ruby-mysql and now everything
works as expected!
Thanks a lot and now finally . Good Night!
S.
On 22 August 2010 23:08, Sven K. [email protected] wrote:
The encoding must also be set in config/database.yml:
adapter: mysql
encoding: utf8Still not good night …
I tried with rails 3 (rc) and this adapter ruby-mysql and now everything
works as expected!
As you figured out, the problem is to do with the old ‘mysql’ gem not
being encoding-aware for Ruby 1.9. (You’re on Ruby 1.9, right?)
As an alternative to ruby-mysql, which is a little slow, you might
want to try the ‘mysql2’ gem, which is an updated version of the
original ‘mysql’ gem, and which has native extensions to hook into the
MySQL C library, making it faster.
Chris
thank You very much for this hint! I’ll give it a try in my next
night-session…greetings
Sven
Oh my god…
first of all, the mysql2 gem works fine - thanks for the hint!
But there’s one more thing: I have lots of notices in my rails app like
“… wurde gelöscht”. But when I have one of those fckng german umlauts
in my controller I get this wonderful character encodings error message.
I’ll try to solve this with a locale and let You know…
greetings
Sven
As an alternative to ruby-mysql, which is a little slow, you might
want to try the ‘mysql2’ gem, which is an updated version of the
original ‘mysql’ gem, and which has native extensions to hook into the
MySQL C library, making it faster.Chris
Hello Chris,
thank You very much for this hint! I’ll give it a try in my next
night-session…
greetings
Sven
I’ll try to solve this with a locale and let You know…
greetings
Sven
hm, within a locale the german umlaute are allowed…
Hi, I began reading this post because i have the same problem:
Just start the aplicacion with new ruby 1.9.2 raises the error
“incompatible character encodings: ASCII-8BIT and UTF-8”…
But I have the problem before reading database, in the main menu when
ruby read “opción” and “menú”
Does anybody this solution, it seems easy.
thanks
Albert C. wrote in post #955265:
Hi, I began reading this post because i have the same problem:
Just start the aplicacion with new ruby 1.9.2 raises the error
“incompatible character encodings: ASCII-8BIT and UTF-8”…
But I have the problem before reading database, in the main menu when
ruby read “opción” and “menú”Does anybody this solution, it seems easy.
thanks
Hi Albert,
I don’t understand this. Where are the words “opción” and “menú”? In the
view there should be no problem.
greetings
Sven
Sven K. wrote in post #935706:
thank You very much for this hint! I’ll give it a try in my next
night-session…greetings
SvenOh my god…
first of all, the mysql2 gem works fine - thanks for the hint!
But there’s one more thing: I have lots of notices in my rails app like
“… wurde gelöscht”. But when I have one of those fckng german umlauts
in my controller I get this wonderful character encodings error message.
First: Display text does not belong in the controller. Keep it in the
views (and perhaps the helpers).
Second: what is the encoding of the source file containing those
characters?
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
Hi, thanks for responding.
It’s very simple, before acces any database, I have a presentation menu,
and a text in the view saying than user have to choose an option:
Seleccione una opción del menú
If I change “ó” with “o” and “ú” with “u” works fine.
It’s not a satisfying solution but whenever I ran into this problem I
added
to the top of the file causing this problem and it worked.
Would love to know how to get rid of all these comments and fix it for
real though
Hi,
Just for your information - switching to ‘mysql2’ gem solved my issue -
I was storing Chinese in my DB…
Plus, mysql2 should be the default mysql adapter of Rails 3 anyways…
Hallo, I face a similar problem, but here mentioned solutions seem to
not work.
When I try to display string with non-ascii chars from a mysql database
in form, sometimes the program stops with the ‘incompatible character
encodings: ASCII-8BIT’ error. This issue appears only at some fileds in
a table! Configuration of all fields is the same (varchar-string or
memo-text, encoding UTF-8).
For example:
I have record with 4 string fields, all have the same content (the same
word). When I try to display them, the ‘incompatible…’ error appears.
When I check their ‘.encoding’, I get UTF-8 for three and ASCII-8BIT for
one! Sometimes, when I render this template again and again, two are
ASCII and Two UTF. Strange - not?
I dont know about any difference among these fields configuration.
Yes, .enforce-coding(‘utf-8’) added to all instance in erb file works,
but it is not natty solution.
The same problem appears both at old project transformed from Ruby
1.8/rails 2.2 and at new project creatd in 5minutes via scaffolding in
ruby1,9,2/rails3.0.3.
The patch ‘ruby_191_hacks.rb’ does not work here, I got the same output
as ‘Posted by Heinz S. (cojones) on 2010-04-06 11:49’
I have realized, that the template (erb file) must be saved in the same
coding, as the field are (i think the comment about UTF widely mentioned
above says to interpeter, that the file is in UTF coding)
My configuration:
Ruby 1.9.2, Rails 3.0.3 (3.0.1 behaves the same), mysql2 0.2.6 driver
(mysql 2.8.1 makes the same problem, mysql-ruby does not work here - it
misses an UNIX constant), both mysql2 and utf8 set in database.yml,
machine WinXP SP3.
Any idea, how to induce ActiveRecord to provide all the fields in the
UTF-8 encoding?
Gjermund Lunder wrote in post #964675:
all,
Thanks for good ideas, but like for Robert K. it’s not working for me
(ruby 1.9.2 and rails 3.0.3).Robert K., check that your tables are of type = MyISAM and CHARACTER SET
utf8 in Mysql.
Er, why MyISAM? That’s generally a poor idea, since you don’t get
transactions or referential integrity.
(Of course, using MySQL itself is IMHO a poor idea…)
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
Sent from my iPhone
all,
Thanks for good ideas, but like for Robert K. it’s not working for me
(ruby 1.9.2 and rails 3.0.3).
Robert K., check that your tables are of type = MyISAM and CHARACTER SET
utf8 in Mysql.
I get the same error as you; the problem appears almost every time, but
suddenly it works for again returning an error.
While we are waiting for a solution; how do you use encoding in the
erb-files? -> “Yes, .enforce-coding(‘utf-8’) added to all instance in
erb file works” If you have the detail text in your file and the in
witch erb-file do I have to put this encoding I would be very thankful.
Thanks again to all.
Gjermund
developer and DBA
Because unfortunately innoDB tables don’t support full text searching of
UTF-8 encoded content. But innoDB tables are more flexible in general.
Source of information:
http://dev.mysql.com/doc/refman/5.1/en/fulltext-restrictions.html and
Ruby On Rails + UTF8 + Mysql | DotMana.
This might not be relevant, but could be.
Robert K. (or others), If you do have have the exact line for the
enforce coding and in witch erb files to put it I would be happy.
PS:
I’ve tried
(Secure UTF-8 Input in Rails - igvita.com) in the
top of my app/views/layout/application.html.erb
I thought this would force the browser to use UFT-8. But not. I’m able
to force the browser to show content after the page is read with right
click- Encoding on screen (but only i just one of the string columns
contains a special characters - strange).
On Mon, Mar 29, 2010 at 5:21 AM, Heinz S. [email protected]
wrote:
layouts/_menu.rhtml but it still throws that error, anyone knows why?
Hey, I would recommend using Ruby 1.9.2 instead of Ruby 1.9.1. Next,
mysql2 gems is not only faster than the ruby-mysql gem but it provides
the following benefits:
The Mysql2 gem is meant to serve the extremely common use-case of
connecting, querying and iterating on results. Some database libraries
out
there serve as direct 1:1 mappings of the already complex C APIs
available.
This one is not.
It also forces the use of UTF-8 [or binary] for the connection [and all
strings in 1.9, unless Encoding.default_internal is set then itll
convert
from UTF-8 to that encoding] and uses encoding-aware MySQL API calls
where
it can.
For more information, please see the following:
Good luck,
-Conrad
–
Anyone know how to add this patch?:
0001-enforced-utf-8-encoding-for-ruby-19-and-mysql-text.patch
(#4683 ASCII-8BIT and UTF-8 in hell - Ruby on Rails - rails)
I’ve never applied such a pacth.
Thanks
Gjermund
Please quote when replying.
Gjermund Lunder wrote in post #964821:
Because unfortunately innoDB tables don’t support full text searching of
UTF-8 encoded content.
I know that, but I didn’t think full-text searching was at issue here.
Perhaps I misread.
The fact that you have to choose is a major reason that I no longer use
or recommend MySQL.
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs