ROR Chinese Solution

Source: Internet
Author: User
Tags mysql query
Rails Learning Notes (6) Chinese garbled solution

Environment:
。 The MySQL 5.0,mysql environment is configured as UTF8, and the table is all used UTF8.
。 IE6.0, FireFox 2.0.2
。 Ruby 1.8.5 + Rails 1.2.3

Error behavior:
。 Use MySQL Query browser to view MySQL data, the Chinese display is normal.
。 The page appears as garbled, the original Chinese place has become a long square
。 Manually adjust the browser's page encoding, you can use the normal display of the page. But after the refresh is garbled.

Workaround: Modify the config/database.yml and add a sentence encoding set below.

Development
Adapter:mysql
Database:chensite_development
Encoding:utf8
Username:root
password:123456
Host:localhost

At this time the data read from the database shows normal, but *.rhtml in the original Chinese but the display into garbled. It is said that the *.rhtml saved in Notepad as a utf-8 format can be resolved, and I am using Radrails, right-click the item in its property page of the info item in the text file encoding to UTF-8. At this time *.rhtml file in the Chinese will become garbled, so it is best to back up, and then the backup of the contents of the file copied and pasted over. Finally, the perfect solution to the Chinese garbled problem.

Note:

1. Some articles say to modify application.rb, add character filter code in Before_filter. I've tried it before, it works. But I think it's easier to revise database.yml.
2. Some articles say to add the following encoding settings to the *.rhtml. I find this sentence can be added without any effect on the page encoding display. < meta HTTP-EQUIV = "Content-type" Content = "text/html"; Charset=utf-8 "/>


3. Others say modify ENVIRONMENT.RB add two lines $KCODE = ' u ' and require ' jcode '. There seems to be no need here. Perhaps this is the old version of the Rails solution.

4. Some people say that when building a table can not use InnoDB, but my statement is as follows, is used InnoDB. No problem found.

CREATE TABLE Modules (
ID int NOT NULL auto_increment,
..........
Expanded tinyint (1) default 0,
Primary KEY (ID)
) ENGINE = InnoDB DEFAULT CHARSET = UTF8;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.