Prev | Current Page 376 | Next

Brad Ediger

"Advanced Rails"

This is generally not
a problem, as characters in the Basic Multilingual Plane can always be encoded in
three or fewer bytes.
PostgreSQL
PostgreSQL is in a similar situation; both the database encoding and client encoding
must be specified. The default encoding is SQL_ASCII. This is a special byteoriented
compatibility encoding; the low-ASCII bytes (0x00 through 0x7F) are
treated as ASCII characters, and the rest (0x80 through 0xFF) are left alone. Because
of the design of UTF-8, the SQL_ASCII encoding is safe to use with UTF-8. However,
it is not optimal, as the database server will not validate any input data.
A new database can be created with UTF-8 encoding, using either the -E option to
createdb or the SQL WITH ENCODING clause:
$ createdb -E UTF-8 new_database
-or-
=> CREATE DATABASE new_database WITH ENCODING 'UTF-8';
Existing databases that were created with another encoding can be dumped and
reloaded to convert them, as with MySQL.
248 | Chapter 8: i18n and L10n
The ActiveRecord PostgreSQL adapter also respects the encoding option to control
client encoding, so remember to set it to UTF-8:
production:
adapter: postgresql
(...)
encoding: UTF-8
Serving UTF-8
Properly serving UTF-8 is a matter of telling the browser that you are using UTF-8.
This is done in two ways:
HTTP Content-type header with a charset parameter
This is the preferred way to set the encoding.


Pages:
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388