开发者

french characters not displaying properly on page in rails 3.0.3

开发者 https://www.devze.com 2023-02-25 05:13 出处:网络
I have created a rails application, in which I am displaying any type of name, name can be anything from person, cars, vegetables, any material.

I have created a rails application, in which I am displaying any type of name, name can be anything from person, cars, vegetables, any material.

So I thought of including some ingredient name like Crème Fraîche, whenever I copy this name from other web page and store in my database, it properly stores it.

While displaying this name on web page, I get some strange characters appearing on the page like Cr�me Fra�che.

I have used charset UTF-8, then also it displays the name like this.

I checked in my database name is stored properly, but on page and in irb it displays the name like this.

I have wasted nearly 5 days on searching fo开发者_C百科r the above problem but didn't succeed. I hope this time I will get some help

Thanks in advance Pankaj


  1. include the following meta tag in the section of your page

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
    

    This tells browsers to use ISO encoding to interpret the text on the page

  2. Even with the correct encoding in the webpage, characters will still display corrupted on a machine where the required fonts are not installed and obviously you cannot be sure what fonts are installed on machines looking at your page

  3. Browsers may also need to be configured. For example, Firefox needs to be told in the Options/Tools/Content section to use the above character set by default

  4. To be absolutely certain your characters will display correctly use the unambiguous HTML code for each non-standard character e.g. instead of Crème use Cr & egrave ; me (NB there should not be spaces between the "&" and the ";" - I had to type it in this way to stop this page from interpreting the code and displaying è).

    This can have implications for web searches and ordering functions in your database. You could store the text as Crème in your database and pass everything through a conversion function before delivering to the HTML page (this will obviously introduce a slight delay in fetching the page). You might also consider having two versions of your data, a raw data version and a display version. Then you could pass new data through the conversion function, store the converted version and have the converted data written to the HTML page.

0

精彩评论

暂无评论...
验证码 换一张
取 消