I am using the money gem in rails to perform some currency conversion.
I'd like to dynamically set the conversion rate so that I can use it in a script.
currency_code = ":SEK"
conversion_rate = @bank.get_rate(:USD, currency_code).to_f
I get this error:
Money::Currency::UnknownCurrency: Unknown currency ':sek'
Which means it's converting the variable to lower case. If I explicitly put in :SEK
I don't have any issues.
I've even tried playing around with this:
cb = "SEK"
conversion_rate = @bank.get_rate(:USD, ":#{cb}").to_f
And
cc = ":SEK"
conversion_rate = @bank.get_rate(:USD, cc.upcase).to_f
However I get the same error.
Any ideas?
bnussey,
I looks like you are passing in your currency as a string instead of a symbol. Try this instead:
If you need to store a string in the database, Ruby can easily convert it to a symbol.