Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -
weirdest error, who’s challenge try , me? spent hours yesterday on , it’s magic. can't believe happening , it's driving me crazy.
btw, using:
- rails 4.2.3
- ruby 2.2.3
- pg 0.18
encoding.default_internal = encoding.default_external = utf-8
config.encoding = 'utf-8'
it has postgres, activerecord , encodings! turns out we’ve been getting these errors whenever create new users on database special characters:
encoding::undefinedconversionerror: "\xc3" ascii-8bit utf-8
\xc3
may vary depending on characters. weird part we’ve set since beginning utf-8. makes no sense , digged it, , used script:
user.all.each |user| user.attributes.each |name, value| if value.is_a? string puts user.email + name.encoding.to_s + value.encoding.to_s end end end
and output of 1 of users, users same:
dr_lottahelp@blahblah.comutf-8utf-8 dr_lottahelp@blahblah.comutf-8ascii-8bit dr_lottahelp@blahblah.comutf-8ascii-8bit dr_lottahelp@blahblah.comutf-8ascii-8bit dr_lottahelp@blahblah.comutf-8utf-8 dr_lottahelp@blahblah.comutf-8utf-8 dr_lottahelp@blahblah.comutf-8utf-8 dr_lottahelp@blahblah.comutf-8utf-8 dr_lottahelp@blahblah.comutf-8utf-8 dr_lottahelp@blahblah.comutf-8utf-8 dr_lottahelp@blahblah.comutf-8utf-8
turns out 3 fields ascii-8bit encoding. absolutely makes no sense me!
(those fields btw, first_name
, middle_name
, last_name
, same in database other text fields got listed on output, don't special treatment).
another funny thing if don't fill of fields, encoding utf-8
value. once fill it, if don't use special characters converted ascii-8bit
.
any suggestions? i've tried every single thing.
thank you.
okay, in case had gem crypt_keeper
. if using special unicode characters such ´
, have explicitly tell gem use utf-8 encode, otherwise store values on database ascii-8bit.
wish got better error message know caused because of that, same problem see someday!
Comments
Post a Comment