Skip to content

Commit

Permalink
Fix missing ExchangeRate
Browse files Browse the repository at this point in the history
  • Loading branch information
Calyhre committed May 15, 2017
1 parent fc10eda commit 47493ca
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ def prices
end

def rates
exchange_rates = ExchangeRate.all
currencies = exchange_rates.pluck(:from).uniq.sort
currencies = Price.pluck(:currency).uniq.sort

csv = CSV.generate(headers: true) do |rows|
rows << [''].concat(currencies)

currencies.each do |from|
row = [from]
currencies.each do |to|
exchange_rate = exchange_rates.find_by(from: from, to: to)
row << (exchange_rate.present? ? exchange_rate.rate : 1)
row << Money.default_bank.get_rate(from, to)
end
rows << row
end
Expand All @@ -55,7 +53,7 @@ def rates

def glossary
countries = Price.pluck(:country).uniq.sort
currencies = ExchangeRate.pluck(:from).uniq.sort
currencies = Price.pluck(:currency).uniq.sort

csv = CSV.generate(headers: true) do |rows|
rows << ['Countries']
Expand Down

0 comments on commit 47493ca

Please sign in to comment.