» Fixing the "NoMethodError: undefined method ‘to_sym’ for false:FalseClass" error when working with I18n in Ruby on Rails
Posted by Kasper Tidemann on Monday 14th of February 2011 06:20:03 PM
If you are in the middle of setting up internationalization in your brand spanking new Ruby on Rails project, you might have added a few locales including a Norwegian one for those lovely people up in northern Scandinavia.
Now, having done this, trying to call <%= I18n.t(‘hello_world’) %>, you might receive the following error:
NoMethodError: undefined method `to_sym’ for false:FalseClass
You look in your YAML files, say en.yml and no.yml, and what you have is this:
# English locale file:
en:
hello_world: ‘Hello world!’
… and…
# Norwegian locale file:
no:
hello_world: ‘Hej verden!’
The above is a classical YAML thing: the no: contained in the no.yml file is interpreted as a boolean, and this renders the Norwegian YAML file useless — and thus, your dandy I18n attempts bork up.
The solution is simple:
# Norwegian locale file:
"no":
hello_world: ‘Hej verden!’
Escape the no: with quotation marks and you’re good to go.






