Prev | Current Page 377 | Next

Brad Ediger

"Advanced Rails"

The server should be configured to
spit out a header like:
Content-Type: text/html; charset=UTF-8
Rails takes care of this for us. As of Rails 1.2, the encoding automatically
defaults to UTF-8.
HTML tag
This method is often used by those who are not able to change their server??™s configuration
to add a proper header. The tag takes the place of the HTTP
header. Put this inside of the tag on your layouts for the same effect as the
header specified previously:

When used by itself, setting a tag is less than ideal. This is because once a
browser reaches this tag, it must re-parse the document from the beginning if its
initial assumption about the encoding was incorrect. (This method works
because the characters likely to be used in an HTML document before the
tag have the same representation in all of the common encodings??”they are the
low ASCII characters.)
However, tags are helpful when used in conjunction with proper server
headers. They allow the browser to determine the proper encoding even if the
file is saved locally (thus removing the header information).
Note that, in the Content-type header, the name ???charset??? is misleading, as this parameter
really specifies the encoding.
Character Set Conversion
You must consider the issue of data you receive from external sources in non-UTF-8
encodings.


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