法语字符在Rails 3.0.3的页面上无法正确显示 [英] french characters not displaying properly on page in rails 3.0.3

查看:96
本文介绍了法语字符在Rails 3.0.3的页面上无法正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个rails应用程序,其中显示了任何类型的名称,名称可以是人,汽车,蔬菜,任何材料中的任何一种.

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.

因此,我想到要包括一些诸如CrèmeFraîche之类的成分名称,每当我从其他网页复制该名称并将其存储在数据库中时,它便会正确存储.

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.

在网页上显示此名称时,页面上出现了一些奇怪的字符,例如Cr.me Fra.che.

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

我使用了字符集UTF-8,然后它也显示了这样的名称.

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

我检查了我的数据库名称是否正确存储,但是在页面和irb中它显示的是这样的名称.

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

我在搜索上述问题上浪费了将近5天,但没有成功. 希望这次我能有所帮助

I have wasted nearly 5 days on searching for the above problem but didn't succeed. I hope this time I will get some help

先谢谢了 潘卡(Pankaj)

Thanks in advance Pankaj

推荐答案

  1. 在页面的部分中包含以下元标记

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

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

这告诉浏览器使用ISO编码来解释页面上的文本

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

即使网页中的编码正确,在未安装所需字体的计算机上,字符仍然会损坏,并且显然您不能确定在查看页面的计算机上安装了哪种字体

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

浏览器可能也需要配置.例如,需要在选项/工具/内容"部分中告知Firefox默认使用上述字符集

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

为绝对确定您的字符将正确显示,请为每个非标准字符使用明确的HTML代码,例如代替Crème使用Cr&刻画;我(注意&"和;"之间不应有空格-我必须以这种方式键入它,以阻止此页面解释代码并显示è).

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 è).

这可能会对数据库中的Web搜索和订购功能产生影响.您可以将文本以Crème的形式存储在数据库中,并在传递到HTML页面之前将所有内容传递给转换函数(这显然会导致页面获取时稍有延迟).您可能还会考虑拥有两个数据版本,即原始数据版本和显示版本.然后,您可以通过转换函数传递新数据,存储转换后的版本,并将转换后的数据写入HTML页面.

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.

这篇关于法语字符在Rails 3.0.3的页面上无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆