现在有哪些选项可以在Ruby和RoR中实现UTF8? [英] What options do exist now to implement UTF8 in Ruby and RoR?

查看:70
本文介绍了现在有哪些选项可以在Ruby和RoR中实现UTF8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在紧跟Ruby的开发之后,我了解到详细的字符编码是在Ruby 1.9中实现的.我现在的问题是:目前该如何使用Ruby与将所有数据存储在UTF8中的数据库进行通话?

背景:我参与了一个新项目,其中至少可以选择Ruby/RoR.但是该项目需要依靠国际化的字符集(遍及许多国家),最好是UTF8.

那么您如何处理呢?预先感谢.

解决方案

"Unicode不错!尽管Rails一直能够存储和显示unicode,但没有任何内容,但截断,反转或获取unicode却有点复杂. UTF-8字符串的确切长度.您需要自己弄弄KCODE,尽管有很多人使它起作用,但它并不像您希望的那样(或什至是预期的)那样简单./p>

因此,由于Ruby直到明年此时才支持多字节,因此Rails 1.2引入了ActiveSupport :: Multibyte用于处理Unicode字符串.在您的字符串上调用chars方法以开始使用字符而不是字节." 解决方案

"Unicode ahoy! While Rails has always been able to store and display unicode with no beef, it’s been a little more complicated to truncate, reverse, or get the exact length of a UTF-8 string. You needed to fool around with KCODE yourself and while plenty of people made it work, it wasn’t as plug’n’play easy as you could have hoped (or perhaps even expected).

So since Ruby won’t be multibyte-aware until this time next year, Rails 1.2 introduces ActiveSupport::Multibyte for working with Unicode strings. Call the chars method on your string to start working with characters instead of bytes." Click Here for more

这篇关于现在有哪些选项可以在Ruby和RoR中实现UTF8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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