2
我在Rail 3.0.12(Ruby 1.8.7)中使用UTF字符時遇到了rails唯一性驗證問題。Rails uniqueness =>真正的編碼問題
這是我的小測試:
正確:
name = "dave"
count = User.where(:name => name).count
u = User.new(:name => name, :gender => "Male")
puts "Current: #{count}/Valid: #{u.valid?}/Errors: #{u.errors.to_a.to_sentence}"
輸出:當前:1 /有效期:假/錯誤:此名稱已被
SQL (0.2ms) SELECT COUNT(*) FROM `users` WHERE `users`.`name` = 'dave'
SQL (0.1ms) SELECT 1 FROM `users` WHERE (`users`.`name` = BINARY 'dave') LIMIT 1
不正確的:
name = "angélique"
count = User.where(:name => name).count
u = User.new(:name => name, :gender => "Male")
puts "Current: #{count}/Valid: #{u.valid?}/Errors: #{u.errors.to_a.to_sentence}"
Outpu T:當前:3 /有效期:真/錯誤:
SQL (0.1ms) SELECT COUNT(*) FROM `users` WHERE `users`.`name` = 'angélique'
SQL (0.1ms) SELECT 1 FROM `users` WHERE (`users`.`name` = BINARY 'angélique') LIMIT 1
似乎在where子句中使用正確的編碼,發現的結果,但對存在的驗證檢查沒有。
任何想法我可以解決這個問題?
而不是存在,不應該是唯一性? –
對不起,我打算說唯一性 – Danny