Chinese garbled characters:
1. The. html. ERB file in the viewsdirectory directly writes Chinese characters and displays garbled characters in the browser.
2) The Chinese characters saved to the MySQL database are displayed normally on the database and interface, but garbled characters are output in the controller.
Solution:
Use the iconv Library
See http://www.kuqin.com/rubycndocument/man/addlib/Iconv.html
Interface Chinese display garbled solution (html. ERB in the Chinese gb2312 encoding, the output needs to be converted to UTF-8 ):
Set
<P> Hello </P>
Change
<P>
<% = Iconv. Conv ("UTF-8", "gb2312", "hello") %>
</P>
The Controller outputs the Chinese language extracted from the database (the database is saved as a UTF-8 Code) to the console Chinese for garbled solution:
Add the following code:
Require "iconv"
Use Time
@ Products = product. All
@ Products. Each do | T |
Iconv. Conv ("gb2312", "UTF-8", T. Title)
End