Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlexander Bromage
Courses Plus Student 4,014 PointsInvalid locale error when using puts price command after using Money in IRB
I am just going through the money section of Ruby Foundation and I have encountered the above error. Here is the code:
>> price = Money.new(1000)
=> #<Money fractional:1000 currency:USD>
>> puts price
I18n::InvalidLocale: :en is not a valid locale
from /Users/alexbromage/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/i18n-0.7.0.beta1/lib/i18n.rb:284:in `enforce_available_locales!'
from /Users/alexbromage/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/i18n-0.7.0.beta1/lib/i18n.rb:151:in `translate'
from /Users/alexbromage/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/money-6.3.0/lib/money/money/formatting.rb:17:in `block in define_i18n_method'
from /Users/alexbromage/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/money-6.3.0/lib/money/money.rb:366:in `to_s'
from (irb):6:in `puts'
from (irb):6:in `puts'
from (irb):6
from /Users/alexbromage/.rbenv/versions/2.1.3/bin/irb:11:in `<main>'
Can someone please tell me what is happening and how I can resolve this. Thanks
notf0und
11,940 PointsAnd, in the case that you don't like the deprecated warning, here's a great SOF post on how to fix that: http://stackoverflow.com/questions/20361428/rails-i18n-validation-deprecation-warning
1 Answer
Alexander Bromage
Courses Plus Student 4,014 PointsThanks Bryan. As I am new I am doing some research to see how to change the version of i18n that I have but it is not clear. I found the article you are referring to but it is written for a ruby application and I am working in the IRB so I am not sure that it will work.
I came across this post: http://stackoverflow.com/questions/20361428/rails-i18n-validation-deprecation-warning
But I cannot locate my i18n file in my system to put the additional command in. Therefore pretty lost! Any further help you could give would be greatly appreciated.
notf0und
11,940 PointsTry doing gem uninstall i18n
, and it may do it right away, or ask you to choose a version, in which case choose 0.7.0beta1. Then you can do gem install i18n
and it will install 0.6.11.
To get to the particular gem files, you'll want to do gem env
which will show you the GEM PATHS to installed gems. To get there, go to finder, press "Go" in the menu bar, then "Go to Folder" and type in the path.
Once there, navigate to wherever the relevant Ruby version folder, keep going into the gems folder, and find i18n 0.6.11. There will be a config.rb file inside where you can find the setting, probably near the bottom.
Set to false, and you should be good to go! Unfortunately, if you wanted to enforce locales, the :InvalidLocale
error will probably still appear. I have no idea how to fix that :(
I hope that's understandable, and that it helps. Let me know what happens :)
Alexander Bromage
Courses Plus Student 4,014 PointsThank you so much Bryan! I ran the uninstall and selected the beta and then only the deprecated error appeared. I can live with that as the result still shows.
notf0und
11,940 PointsGlad to hear that fixed it. If I ever do find out how to get enforced locales without errors, I'll try to remember to update you on this post :)
notf0und
11,940 Pointsnotf0und
11,940 PointsSeems you have a beta version of i18n installed. Try using 0.6.11 (works on my computer, with simply a deprecated warning).