"invalid multibyte char" error when using greek characters in Rails enum

1.4k views Asked by At

This:

enum UnitOfMeasure: [ :g, :mg, :µg]

gives:

Syntax Error: invalid multibyte char (US-ASCII)

I hope I won't be forced to add a table just for this.

2

There are 2 answers

3
tadman On

If you're not using a newer version of Ruby where UTF-8 encoding is the default you may need to add this to your file:

# encoding: UTF-8

If that doesn't fix it, be sure that your file is actually saved as UTF-8.

1
Hector Acosta On

In my case I was running code directly in the console, I which I couldn't just add # encoding: UTF-8, the solution under this situation is to set 2 environment variables:

$ export LC_ALL=en_US.UTF-8
$ export LANG=en_US.UTF-8

Then you just only need to run rails c, and you'll be able to use the characters you desire, in my case I tried to use Russian characters.