Ruby on Rails Learning: Solving Chinese garbled problems __ garbled problem

Source: Internet
Author: User
Tags ruby on rails
Beginner rails, simple to do an example, found that there is a Chinese problem.
The general Chinese question is categorized as follows:
1, the page can not display Chinese, the production of Chinese garbled
2, MySQL database using UTF8, the page using UTF8, database preservation is garbled, but the page shows normal.
3, the time format on the page of the Chinese display generated garbled.
Open: application.rb: Modify the code as shown below:
1 class Applicationcontroller < Actioncontroller::base
2 Before_filter:set_charset
3 def Set_charset
4 @headers ["content-type"] = "text/html;" Charset=utf-8 "
5 End
6 end adds code control to the page (*.rhtml) at the same time:
< meta HTTP-EQUIV = "Content-type" Content = "text/rhtml"; Charset=utf8 "/>

At the same time, when the page is saved, the encoding is converted to UTF8 format.
After the above work, using the MySQL database client tools navicat to view the database, you will find the database stored in Chinese data will be garbled, and therefore need further processing:
1, the database is built using UTF8 code to build the library, while the table or Guide table should pay attention to the use of UTF8 code.
2, the use of NAVICAT connection to the database in the advanced settings in the selection encoding encoding for UTF8, while eliminating using MySQL character set default options, and then connect.
The above settings will display normal Chinese in the database. The page will also be displayed in Chinese, but you will find that there are still some small problems with the display of time. Therefore, the conversion format (original_date.strftime ("%y/%m/%d")) is required for the output time.
Complete.

Http://www.blogjava.net/shmily432685/archive/2006/09/27/72261.aspx

Related Article

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.