G
G
Georgy Khromchenko2012-02-20 01:34:30
Ruby on Rails
Georgy Khromchenko, 2012-02-20 01:34:30

Encoding of serializable attributes in Rails/Ruby 1.9.3?

On Habré, many already write that they completely abandoned Ruby 1.8.7 and switched to the 1.9.x branch.
I decided to try to translate Rails 3.1 projects to 1.9.3
- I added a comment with encoding to all * .rb using a special gem -
Registered

Encoding.default_external = Encoding::UTF_8<br/>
Encoding.default_internal = Encoding::UTF_8<br/>

However, I still get the ill-fated incompatible character encodings: UTF-8 and ASCII-8BIT
I suspect the glitch is in places where serializable model attributes are declared in the code
Something like the
serialize :answers<br/>
MySQL connection encoding is set to UTF-8
Doing projects on the 1.9.x branch, how did you deal with this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Georgy Khromchenko, 2012-02-20
@Mox

Further investigation showed that
there is a text field in the database where Ruby 1.8.7 serialized the data. Here is its content. It looks like the deserialization of this in 1.9.x does not work correctly. I'll try to read separately in the console, make force_encoding and save.
---
- !binary |
0J7QtNC40L0t0LTQstCw
итд

A
Andrey Shaydurov, 2012-02-20
@GearHead

1) magick comment should be added only to those files that contain explicit non-Latin characters. switch to I18n and don't write Russian comments, and you can forget about this comment.
2) from a couple of my rail projects on 1.9.3: why is this at all? 3) if somewhere in the code explicitly and there is a mention of utf-8, then only in config/application.rb: 4) check carefully that your view-templates are all in utf-8, and that forms contain magick utf- 8 attributes. probably, you receive data from the client in a single-byte encoding. 5) use a debugger. locate the error. at least bring the trace here. I can't say anything more.
$ grep -iR 'Encoding.default_internal' *
$

config.encoding = "utf-8"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question