gpt4 book ai didi

html - 在 Rails 应用程序中设置字符集

转载 作者:太空狗 更新时间:2023-10-29 13:40:44 24 4
gpt4 key购买 nike

我正在尝试在 RoR 应用程序的 html View 中设置我的字符集。我已经通过 meta equiv 标签配置了字符集:
**meta http-equiv="Content-Type"content="text/html; charset=iso-8859-1"**

它没有用,所以我尝试更改我的 .htaccess(它是一个在 apache 下运行的 RoR 应用程序),但这是我的问题。通常我可以使用以下语句:AddType '文本/html; charset=ISO-8859-1' html

但问题是,众所周知,RoR 没有“文件扩展名”,这打破了这个 .htaccess 解决方案。有人知道另一种在布局模板或 View 中设置字符集的方法吗?

最佳答案

让您的 Rails 应用程序设置 Content-type header ,这样您就无需担心 Apache 正在做什么。

response.headers['Content-type'] = 'text/html; charset=utf-8'

您可能还想添加

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

到页面本身,这样如果有人将它保存到磁盘,它将加载正确的字符集。

关于html - 在 Rails 应用程序中设置字符集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/901097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com