Rails 不同的产品数据库 currency/pricing

Rails product database with different currency/pricing

我的 Rails 应用程序中有一个产品 table 具有以下列:

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

当我开发该应用程序时,它仅适用于单一国家和单一货币。现在我想支持更多基于地理国家/地区的货币,但使用我当前的数据库结构最好的方法是什么?

有人推荐我使用 Money gem 但它只是货币兑换。我真正想要的是为不同的 currencies/countries.

手动设置不同的定价

关于最好的方法有什么建议吗?

更新:我们不打算拥有超过 20 种产品,而且我们的定价有点高,所以我们不关心汇率 - 相反,我们希望根据产品的强度有不同的定价某些国家/地区的经济

尝试全球化 gem 以获得需要支持多 languages/regions/currencies 的内容。 https://github.com/globalize/globalize

根据我的评论,我应该在 productscurrencies 之间使用联接 table prices,并使用 the has_many :through Association,如中所示文档。

连接模型 Price 有列:

| product_id | currency_id | value |

Price关系:

class Price < ApplicationRecord
  belongs_to :product
  belongs_to :currency
end

当然需要模型Currency,可以存储,名称,国家,符号,国旗,...