本文介绍了为什么Rails中的默认编码不是UTF-8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 当我在控制器中使用UTF-8字符(大部分时间土耳其字符)时,我必须在每个控制器的顶部添加 #encoding:utf-8 文件。 为什么Rails不会默认使用这个? 编辑:我知道它不是关于Rails,而是关于Ruby。 > 解决方案 Ruby 2.0默认是UTF8。否则你必须在1.9中表示。根据naruse: 默认脚本编码更改。 更改为UTF8 [#6679] 在Ruby 1.9中,默认脚本编码是 US-ASCII。考虑以下的利弊后,我们将其更改为UTF-8。 UTF-8默认是方便的,因为大多数现代应用程序使用UTF-8这个更改不影响任何1.9代码如果魔术注释到位。没有魔术注释的1.9 中的默认脚本编码是US-ASCII或ASCII-8BIT。在UTF-8中,有些字符串操作会变得更慢。 源: Rubyist杂志 When I use UTF-8 characters (most of the time Turkish characters) in controllers, I have to add #encoding: utf-8 on the top of each controller file.Why doesn't Rails use this as a default?edit: I have learnt that it is not about Rails, it is about Ruby. 解决方案 Ruby 2.0 is UTF8 by default. Otherwise you must signify that in 1.9. According to naruse: The default script encoding change. Default script encoding (when magic comment is not specified) is changed into UTF8[#6679] In Ruby 1.9, the default script encoding is US-ASCII. We changed it to be UTF-8 after considering the following pros and cons. UTF-8 default is convenient because the majority of modern application uses UTF-8 This change doe not impact any 1.9 codes if Magic Comments are in place. The default script encoding in 1.9 without Magic Comment is either US-ASCII or ASCII-8BIT. In UTF-8, then some string manipulation could become slower.Source: Rubyist Magazine 这篇关于为什么Rails中的默认编码不是UTF-8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-28 07:15
查看更多