我在处理 ruby on rails 应用程序中的字符集时遇到问题,特别是在我的模板中。来 self 的数据库的代码工作正常,但位于我的 View 中的 ç ~ 之类的代码不起作用。我在我的代码中添加了以下代码
我添加了一个类似的功能,但仍然无法正常工作我的 application.rhtml 中有 ç ~ 代码无法正常工作。
before_filter :configure_charsets
# Configuring charset to UTF-8 def configure_charsets
headers["Content-Type"] = "text/html; charset=UTF-8"
end
我还添加了 meta http-equiv html 到 utf-8 和一个 .htaccess 参数 AddDefaultCharset UTF-8
还是不行,还有其他提示吗?
最佳答案
把这段代码放在你的配置中(environment.rb
)
Rails::Initializer.run do |config|
config.action_controller.default_charset = "iso-8859-1"
end
这样就可以了。
此外,删除 layouts/application.html
关于ruby-on-rails - ruby on rails x 字符集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/901884/