RubyMoney/money · error · Money::Bank::UnknownRate
No conversion rate known for '#{from.currency.iso_code}' ->
Error message
No conversion rate known for '#{from.currency.iso_code}' -> '#{to_currency}' What it means
Error "No conversion rate known for '#{from.currency.iso_code}' -> '#{to_currency}'" thrown in RubyMoney/money.
Source
Thrown at lib/money/bank/variable_exchange.rb:122
#
# # Exchange 100 USD to CAD:
# bank.exchange_with(c1, "CAD") #=> #<Money fractional:12451 currency:CAD>
#
# # Exchange 100 CAD to USD:
# bank.exchange_with(c2, "USD") #=> #<Money fractional:8031 currency:USD>
def exchange_with(from, to_currency, &)
to_currency = Currency.wrap(to_currency)
if from.currency == to_currency
from
elsif (rate = get_rate(from.currency, to_currency))
fractional = calculate_fractional(from, to_currency)
from.dup_with(
fractional: exchange(fractional, rate, &),
currency: to_currency,
bank: self,
)
else
raise UnknownRate, "No conversion rate known for '#{from.currency.iso_code}' -> '#{to_currency}'"
end
end
def calculate_fractional(from, to_currency)
BigDecimal(from.fractional.to_s) / (
BigDecimal(from.currency.subunit_to_unit.to_s) /
BigDecimal(to_currency.subunit_to_unit.to_s)
)
end
def exchange(fractional, rate, &)
ex = fractional * BigDecimal(rate.to_s)
if block_given?
yield ex
elsif @rounding_method
@rounding_method.call(ex)
else
exView on GitHub (pinned to 26e2829c34)
When it happens
Trigger: Thrown at lib/money/bank/variable_exchange.rb:122 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of RubyMoney/money@26e2829c34 (2026-08-23).
Data as JSON: /api/errors/390f439ec4ee395f.
Report an issue: GitHub.