为什么ActiveRecord的和/或MySQL具有这种性格有问题? [英] Why is ActiveRecord and/or MySQL having a problem with this character?

查看:310
本文介绍了为什么ActiveRecord的和/或MySQL具有这种性格有问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我插入某些字符串的API调用到我的数据库进来,它们会在特定的字符切断。这与红宝石1.8.7。我把一切都设置为utf8的应用范围和MySQL的。我通常不会有任何问题,进入UTF8内容到数据库的应用程序的其他部分。

这应该是厄尔尼诺索尔达多和LaMuñeca。如果我将它插入到数据库中,只有这使得它:11厄尔尼诺索尔达多和La木

>>名称
=>11厄尔尼诺索尔达多和La木?ECA(1).MP3
>>名称[20..20]
=>U
>>名称[21..21]
=>\ 361
>>名称[22..22]
=>E

  1. 是一个utf8字符?
  2. 我知道,红宝石1.8没有编码知道,但说实话我总是忘了这会如何影响我 - 我总是只设置一切在所有其他层为utf8,一切都很好。为什么这个没有工作了吗?

更新

CORRECTION--我错了,它不是从API的到来,它是从文件系统的到来。

的错误恩codeD字符从即将在屋内的!

新问题:我怎样才能从文件#路UTF8字符

解决方案

您在某种程度上得到一个拉丁语-1 (AKA ISO-8859-1) N ,而不是一个UTF-8 N 。在拉丁美洲-1 N 是八进制361(因此你的单字节\ 361)。在UTF-8小写波浪线n应 \ 303 \ 261 (即字节八进制或0xc3和0xb1十六进制0303和0261)。

您可能必须先从语言Iconv打在Ruby端,以确保您在UTF-8得到的一切。

When I insert certain strings coming in from API calls into my db, they get cut off at certain characters. This is with ruby 1.8.7. I have everything set to utf8 app-wide and in MySQL. I typically don't have any problem entering utf8 content into the DB in other parts of the app.

It's supposed to be "El Soldado y La Muñeca". If I insert it into the db, only this makes it in: "11 El Soldado y La Mu".

>> name
=> "11 El Soldado y La Mu?eca(1).mp3"
>> name[20..20]
=> "u"
>> name[21..21]
=> "\361"
>> name[22..22]
=> "e"

  1. is that a utf8 character?
  2. i know that ruby 1.8 isn't encoding aware, but to be honest i always forget how this should affect me -- i always just set everything at all the other layers to utf8 and everything is fine. WHY THIS NO WORK NOW?

update

CORRECTION-- i was wrong, it's not coming from the api, it's coming from the file system.

the wrongly-encoded character is coming from inside the house!

new question: How can I get utf8 characters from File#path

解决方案

You are somehow getting a Latin-1 (AKA ISO-8859-1) ñ rather than a UTF-8 ñ. In Latin-1 the ñ is 361 in octal (hence your single byte "\361"). In UTF-8 that lower case tilde-n should be \303\261 (i.e. bytes 0303 and 0261 in octal or 0xc3 and 0xb1 in hex).

You might have to start playing with Iconv in the Ruby side to make sure you get everything in UTF-8.

这篇关于为什么ActiveRecord的和/或MySQL具有这种性格有问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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