rails 3.1多种货币

我必须在应用程序中添加更多货币,就像在这个网络应用程序http://www.designconnected.com/上一样,它会以你选择的任何货币转换价格并保持这种方式。 我一直在寻找已经过时的gem,教程找不到任何东西,在stackoverflow中有一些关于它的问题,但没有一个得到我需要的东西。

如果有人知道更好的gem,最近发布了……请告诉我。 或者如果没有它的gem,我应该将currency_id添加到current_user,以便应用程序显示该用户的正确货币..但是我从哪里获取货币汇率…我一直在寻找一个解决方案3天了,什么都没有。

谢谢你的任何建议..

这个url已经过检查:

https://stackoverflow.com/questions/1368010/rails-currency-gem-or-plugin

Rails 3 – 多种货币

https://github.com/RubyMoney/money

结合https://github.com/RubyMoney/google_currency的最后一个看起来就像我需要的那个……但是现在是获得如何使用它的教程的最佳时机。

如果无法找到/获得有关此内容的完整教程,请帮助了解如何启动它的一些想法。 谢谢。

https://github.com/RubyMoney/money-rails和https://github.com/RubyMoney/google_currency是要走的路。 这不是我的问题或问题,但无论如何,这是我现在最接近的答案。 这是我为实现这一目标所做的一些步骤:

gem文件中

gem "json" #if you don't have it gem "money" gem "google_currency" 

config/initializers创建一个money.rb文件

 require 'money' require 'money/bank/google_currency' require 'json' MultiJson.engine = :json_gem Money.default_bank = Money::Bank::GoogleCurrency.new 

product.rb (或任何需要转换价格的型号)

 composed_of :price, :class_name => "Money", :mapping => [%w(price price), %w(currency currency_as_string)], :constructor => Proc.new { |price, currency| Money.new(price || 0, currency || Money.default_currency) }, :converter => Proc.new { |value| value.respond_to?(:to_money) ? value.to_money : raise(ArgumentError, "Can't convert #{value.class} to Money") } 

并在视图文件中:

 <%= number_to_currency(product.price.exchange_to(:EUR)) %> 

例如,我有一个IT语言环境(意大利语) – 意大利货币现在是欧元:

您将以欧元转换价格..它对我来说真的很好,货币gem使用Google_currency转换欧元的价格,并且语言环境yml文件更改此区域设置的货币,因此您的价格看起来像XXX,XX欧元而不是$ XXX,XX。

要为每个区域设置显示正确的货币,您需要添加:

 it: number: currency: format: format: "%n %u" unit: "EUR" 

it.yml文件中或您拥有该国家/地区货币的其他语言。

你可能不需要gem。 您可以使用此处说明的url在代码中的任意位置直接拨打谷歌的货币API。 这可以在您的模型中完成,也可以直接在视图中通过AJAX完成。

http://motyar.blogspot.com/2011/12/googles-currency-converter-and-json-api.html