<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d4684235500622716427\x26blogName\x3dCaiwangqin\x27s+blog\x26publishMode\x3dPUBLISH_MODE_HOSTED\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://blog.caiwangqin.com/search\x26blogLocale\x3dzh_CN\x26v\x3d2\x26homepageUrl\x3dhttp://blog.caiwangqin.com/\x26vt\x3d3393395200455623441', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Caiwangqin's blog

Focus on Cloud Service, Smart Hardware, Architecture, Technic and beyond…

Multibyte for Rails : ROR中文应用必须的插件

2006年9月27日星期三

问题的出现:


Rails中处理中文时,会作为单字节处理,如:


“中文”.size => 4


“中文”.reverse => “\304\316\320\326″


解决方法:


安装插件 Multibyte for Rails 后,在rails中使用String#chars访问,如:


“中文”.chars.size => 2


“中文”.chars.reverse => “文中”


其它:


由于其性能并未得到测试,请根据你的应用选择使用。


Resource:


http://wiki.rubyonrails.com/rails/pages/HowToUseUn…


https://fngtps.com/svn/multibyte_for_rails/


http://multibyterails.org/documentation/


标签:

posted by Jesse Cai, 上午6:36

0 Comments:

发表评论

订阅 帖子评论 [Atom]

<< 主页