How can I use German umlauts ä ö ü in rails console?


#1

Hi there

I have a list of user_ids and updated names, which I would like to run through console like this:

User.find(4).update(name: 'Updated Name')

My Question: Some of the names contain special characters like German umlaut ä ö ü, and those typing or pasting into console cause some strange behaviour. ü for example lets a history command appear. How can I update those names through console?


(Robin Ward) #2

What terminal program are you using? I just tried in mine and was able to use ä ö ü properly.


#3

I use iTerm with oh-my-zsh, but I just tried it with the macOS terminal, same behavior.

I can also use üöä in my terminal window, unless I enter the rails console in the docker-container on my production server.

  • on my local computer: works
  • on my local computer (development) in the rails console: works
  • on the production server (ssh): works
  • on the production server in the docker container: works
  • on the production server in the docker container in the rails console: doesn’t work

(Robin Ward) #4

I just shelled to one of my production discourse instances on digital ocean, entered the docker container and ran rails c and I was able to search for the character:

root@fishtank:/var/discourse# ./launcher enter app
root@fishtank-app:/var/www/discourse# rails c
[1] pry(main)> User.where(username: 'ä')
=> []

I’m not sure why it doesn’t work on your setup unfortunately.


#5

Thanks for looking into it. I really appreciate that.

That’ interesting and confusing.

My app is on a linode and I followed the INSTALL-cloud Guide

Here is my terminal-history:

➜  ~ ssh c...n@xxx.xxx.xxx.xxx
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.9.15-x86_64-linode81 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
Last login: Mon Jul 10 19:29:38 2017 from 78.94.0.50
c...n@solawiforum:~$ cd /var/discourse/
c...n@solawiforum:/var/discourse$ üöä^C
c...n@solawiforum:/var/discourse$ sudo ./launcher enter app
root@solawiforum-app:/var/www/discourse# üöä^C
root@solawiforum-app:/var/www/discourse# rails c
[1] pry(main)> User.where(username: '

When I try to enter or paste ä i get a warning beep sound and nothing happens.


(Héctor Fernández) #6

Try this: in the preferences of iTerm make sure you have set the option key to Normal and not +Esc.


#7

That’s not the issue, I think.

It’s working in iTerm everywhere but in the rails console inside the docker app on the production server.


(Robin Ward) #8

I’m not a linux pro but it’s possible some environment variables are changing the way terminals are working and that is messing things up. I saw something similar when trying to get 256 color terminals working.


#9
[1] pry(main)> ENV['LANG']
=> "de_DE.UTF-8"
[2] pry(main)> Encoding.default_internal
=> #<Encoding:UTF-8>
[3] pry(main)> Encoding.default_external
=> #<Encoding:UTF-8>
[4] pry(main)> "a".encoding
=> #<Encoding:UTF-8>

(Héctor Fernández) #10

Could it be that the difference with the docker locale causes problems (de_DE.UTF-8 vs en_US.UTF-8)?


#11

Interesting:

c...n@solawiforum:/var/discourse$ locale
LANG=en_US.UTF-8
[...]
c...n@solawiforum:/var/discourse$ sudo ./launcher enter app
root@solawiforum-app:/var/www/discourse# locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=de_DE.UTF-8
[...]

Would you change the docker locale or the ubuntu locale?


#12

Now, both ubuntu and docker locales are set to LANG=de_de.UTF-8, but it’s the same.

c...n@solawiforum:/var/discourse$ locale
LANG=de_DE.UTF-8
[...]
c...n@solawiforum:/var/discourse$ sudo ./launcher enter app
root@solawiforum-app:/var/www/discourse# locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=de_DE.UTF-8

(Eli the Bearded) #13

That shouldn’t make a difference for entering text. UTF-8 is UTF-8 is a way to understand the characters in a bytestream. en vs de might change things like using comma instead of full stop for marking decimal place in numbers, but not something as low as what the characters are.