1

I have a product table in my Rails application with following columns:

table "products"
t.string   "name"
t.text     "description"
t.integer  "price"

When I was developing the app, it was just for a single country and for single currency. Now I would like to support more currencies based on geo country but what is the best way to do it with my current database structure?

It was recommended to me to use Money gem but it is just money exchange. What I really want is to set up manually different pricing for different currencies/countries.

Any recommendation on the best way to do it?

Update: We don't plan to have more than like 20 products and our pricing is a bit higher so we don't care about the exchange rate - rather we would like to have different pricing based on how strong is the economy in certain countries

Petr
  • 1,853
  • 2
  • 25
  • 49
  • I suggest you take a look https://stackoverflow.com/questions/3139879/how-do-i-get-currency-exchange-rates-via-an-api-such-as-google-finance if you mind exchange rates. – iGian Jun 08 '18 at 06:57
  • Or set maybe set up a table with `product_id | currency_id | price`, but becomes a big deal to keep update if you have a lot of products and currencies. – iGian Jun 08 '18 at 07:02
  • @iGian thank you for the idea.. I like the product_id | currency_id | price... you could describe it in detail in the answer section and I will mark it as the correct answer if you don't mind – Petr Jun 30 '18 at 06:08
  • Why not? Hope the answer could help. Or back in touch. Thank you. – iGian Jun 30 '18 at 13:22

2 Answers2

1

Following up to my comment, I should use the join table prices between products and currencies, with an the has_many :through Association, like shown in documentation.

The join model Price has columns:

| product_id | currency_id | value |

Price relations:

class Price < ApplicationRecord
  belongs_to :product
  belongs_to :currency
end

Of course, the model Currency is required, which can store, name, country, symbol, flag, ...

iGian
  • 11,023
  • 3
  • 21
  • 36
0

Try Globalize gem for content need supporting multi languages/regions/currencies. https://github.com/globalize/globalize

AustintheCleric
  • 349
  • 3
  • 15