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 trialMichael Velasquez
1,868 PointsIssue with RubyMoney after installing the gem
After installing the gem, i did the "require the gem", etc in irb. I follow the video exactly but for some reason, i'm returning price = Money.new(1000) as fractional and not as cents. What could be causing this? I'm guessing the video might be outdated and/or the gem is has gone though some new versions... but i haven't checked. Curious if anyone else has seen this issue?
4 Answers
cp88
5,039 PointsI get the same:
treehouse:~ $ irb
irb(main):001:0> require "money"
=> true
irb(main):002:0> price = Money.new(1000)
=> #<Money fractional:1000 currency:USD>
irb(main):003:0> puts price
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
10.00
=> nil
irb(main):004:0>
Chris Shaw
26,676 PointsHi Michael,
What is the exact value you're getting back as in the video when Money.new(1000)
is defined the expected output would be as follows.
>> price = Money.new(1000)
=> #<Money cents:1000 currency:USD>
>> puts price
10.00
=> nil
Alexander Bromage
Courses Plus Student 4,014 PointsI am having the same problem I get:
>> require 'Money'
=> true
>> 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>'
This command in IRB: ```ruby irb(main):006:0> I18n.enforce_available_locales = false => false
Remove the problem for that session of IRB but if I restart IRB the error comes back again.
Any help would be appreciated!
Lindsay Terrell
9,888 PointsFollowing this forum post solved the problem for me: https://teamtreehouse.com/forum/using-the-gem-money-it-will-not-allow-me-to-use-puts-price