# Utf8 problem

**URL:** <https://www.ruby-forum.com/t/utf8-problem/183425>\
**Category:** Rails\
**Created:** [February 13, 2010, 7:04pm UTC](https://www.ruby-forum.com/t/utf8-problem/183425 "2010-02-13T19:04:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kouzma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/6f9a4e/32.png) [@kouzma](https://www.ruby-forum.com/u/kouzma)\
**Post date:** [February 13, 2010, 7:04pm UTC](https://www.ruby-forum.com/t/utf8-problem/183425/1 "2010-02-13T19:04:57Z")

</div>

Hello.  
I’ve started to study ruby and rails.

I added string to the model:  
validates\_length\_of :first\_name, :within =\> 3…64, :too\_long =\>  
‘long’, :too\_short =\> ‘short’  
It works.

I changed error messges (I need to use russian words in it):  
validates\_length\_of :first\_name, :within =\> 3…64, :too\_long =\>  
‘Ð”Ð»Ð¸Ð½Ð½Ð¾Ðµ’, :too\_short =\> ‘ÐšÐ¾Ñ€Ð¾Ñ‚ÐºÐ¾Ðµ’  
It doesn’t work. The error is:  
… app/models/user.rb:3: invalid multibyte char (US-ASCII) …

Tried to find decision with google. Tried to use monkey patches:

> <https://gist.github.com/andre/273741>

I dont’t now if my using was correct: I just created 3 files  
(patch.rb, fix\_params.rb, fix\_renderable.rb) in the folder config/  
initializers - I didn’t require it anywhere (I think, that it  
happends automatically).  
Error changed to:  
… incompatible character encodings: ASCII-8BIT and UTF-8 …  
This error is in ruby, not in rails:  
D:/WebProgramming/Ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/  
lib/active\_support/core\_ext/string/output\_safety.rb:34:in `concat’  
…

My configuration:  
ruby 1.9.1  
rails 2.3.5  
Windows XP  
Redactor is Aptana - it uses utf8 as default

What have I to do to russian words become to work (utf8)? I want to  
find decision for Windows Ruby 1.9.1

---

<div class="post-metadata">

**Author:** ![kouzma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/6f9a4e/32.png) [@kouzma](https://www.ruby-forum.com/u/kouzma)\
**Post date:** [February 14, 2010, 3:01am UTC](https://www.ruby-forum.com/t/utf8-problem/183425/2 "2010-02-14T03:01:25Z")

</div>

kouzma wrote:

> Hello.  
> I’ve started to study ruby and rails.
> 
> I added string to the model:  
> validates\_length\_of :first\_name, :within =\> 3…64, :too\_long =\>  
> ‘long’, :too\_short =\> ‘short’  
> It works.
> 
> I changed error messges (I need to use russian words in it):  
> validates\_length\_of :first\_name, :within =\> 3…64, :too\_long =\>  
> ‘Ð”Ð»Ð¸Ð½Ð½Ð¾Ðµ’, :too\_short =\> ‘ÐšÐ¾Ñ€Ð¾Ñ‚ÐºÐ¾Ðµ’  
> It doesn’t work. The error is:  
> … app/models/user.rb:3: invalid multibyte char (US-ASCII) …
> 
> Tried to find decision with google. Tried to use monkey patches:  
> [ruby\_191\_hacks.rb · GitHub](http://gist.github.com/273741)  
> I dont’t now if my using was correct: I just created 3 files  
> (patch.rb, fix\_params.rb, fix\_renderable.rb) in the folder config/  
> initializers - I didn’t require it anywhere (I think, that it  
> happends automatically).  
> Error changed to:  
> … incompatible character encodings: ASCII-8BIT and UTF-8 …  
> This error is in ruby, not in rails:  
> D:/WebProgramming/Ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/  
> lib/active\_support/core\_ext/string/output\_safety.rb:34:in `concat’  
> …
> 
> My configuration:  
> ruby 1.9.1  
> rails 2.3.5  
> Windows XP  
> Redactor is Aptana - it uses utf8 as default
> 
> What have I to do to russian words become to work (utf8)? I want to  
> find decision for Windows Ruby 1.9.1

Have you tried putting

# encoding: utf-8

as the first line of that model’s file?

[http://blog.nuclearsquid.com/writings/ruby-1-9-encodings](http://blog.nuclearsquid.com/writings/ruby-1-9-encodings) and  
[http://blog.grayproductions.net/articles/ruby\_19s\_string](http://blog.grayproductions.net/articles/ruby_19s_string) are good  
articles to help beginning to understand Ruby 1.9’s encoding  
agnosticism.
