nevan king
nevan king

Reputation: 113777

Avoid using # encoding: UTF-8

I ran into a problem with a Rails controller where it choked on a Unicode string:

syntax error, unexpected $end, expecting ']' ...conditions => ['url like ?', "%日本%"])

The solution to this problem was to set the encoding at the top of the controller file using

# encoding: UTF-8

Is there any way to set this globally? I keep on getting into trouble by forgetting to set it in files. Alternatively, is there a default somewhere that will make sure that all strings are thought of as Unicode? Are there any problems with setting everything to be Unicode?

Upvotes: 2

Views: 485

Answers (2)

ivalkeen
ivalkeen

Reputation: 1411

You can try setting environment variable RUBYOPT to -Ku value:

export RUBYOPT="-Ku"

Upvotes: 2

sawa
sawa

Reputation: 168249

In less than a month, Ruby 2.0 will be released, which will have UTF-8 as the default encoding. Then, you will not need to do that any more.

Upvotes: 4

Related Questions