ruby-on-rails – 为什么升级到Rails 3后所有字符串都是ASCII-8BIT?

我升级到RoR 3.0.1和Ruby升级到1.9.2.现在我视图中的所有字符串都是ASCII-8BIT?

我相信我的应用程序设置为使用UTF 8

application.rb中

config.encoding = "utf-8"

database.yml的

development:
  adapter: mysql
  encoding: utf8

我在跑

OS X
RVM rvm 1.0.16 
Ruby ruby-1.9.2-p0
Rails 3.0.1

我希望编码是UTF 8而不是ASCII

business.desc.encoding
# ASCII-8BIT

由于1.9.x可以连接不同编码的字符串,我们会看到很多这样的错误.

<p class="description"><%= truncate(business.desc,:length => 17) %></p>

错误

incompatible character encodings: ASCII-8BIT and UTF-8

activesupport (3.0.1) lib/active_support/core_ext/string/output_safety.rb:74:in `concat'
activesupport (3.0.1) lib/active_support/core_ext/string/output_safety.rb:74:in `concat'
actionpack (3.0.1) lib/action_view/template/handlers/erb.rb:14:in `<<'
app/views/browse/businesses.html.erb:15:in `block in _app_views_browse_businesses_html_erb___1616718260917998189_2173630500__1134905695726531092'
app/views/browse/businesses.html.erb:3:in `each'
app/views/browse/businesses.html.erb:3:in `each_with_index'
app/views/browse/businesses.html.erb:3:in `_app_views_browse_businesses_html_erb___1616718260917998189_2173630500__1134905695726531092'

还有其他人有这个问题吗? ruby-1.9.2-p0是否使用正确的版本?

谢谢!

解决方法

您需要将其添加到每个.rb文件:
<% # coding: UTF-8 %>

我使用gem magic_encoding.

$cd app/ 
$magic_encoding

默认值为UTF-8,但您可以指定任何您想要的参数.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...