
Security News
Researcher Exposes Zero-Day Clickjacking Vulnerabilities in Major Password Managers
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
TODO: Write a gem description
Add this line to your application's Gemfile:
gem 'multi_currency', github: 'xsoulsyndicate/multi_currency'
And then execute:
$ bundle
NOTE: Still in development
For example you already had 'price' attribute in Product model and want to add multi currency support for it.
class Product < ActiveRecord::Base
attr_accessible :price, :price_rate_date, :price_currency, :price_source_amount, :price_source_currency # For Rails 3
multi_currency_for [:price]
before_save :do_currency_exchange
end
Add required migration. Create a migration and add this columns:
add_column :products, :price_rate_date, :date
add_column :products, :price_currency, :string
add_column :products, :price_source_amount, :decimal
add_column :products, :price_source_currency, :string
All columns are prefixed with :price in this case. Adjust the prefix according to the column name.
So when you save a product, you can just do it like this.
product = Product.new(price_source_amount: 100, price_source_currency: 'USD')
product.save
The required attributes to set is only _source_currency and _source_amount. You can set _rate_date if you want to specify in which date the currency exchange rate will be fetched.
After that you can get price in any currency:
product = Product.first
product.price_in('EUR')
Default exchange rate is rate from _rate_date column. If you want to get price with currency exchange rate in other date, just pass a date:
product.price_in('EUR', Date.yesterday)
You can also get total of price in other currency:
Product.sum_price('EUR', Date.today)
Add an initializer e.g config/initializers/multi_currency.rb
MultiCurrency.configure do |config|
config.default_currency = 'eur'
end
Set default_converter = 'Openexchange' on config/initializers/multi_currency.rb
MultiCurrency.configure do |config|
config.default_converter = 'Openexchange'
end
You will need APP ID to use OpenExchangeRate, you can get from https://openexchangerates.org for free. Set OPEN_EXCHANGE_RATES_APP_ID environment variable.
OPEN_EXCHANGE_RATES_APP_ID = 'APP_ID'
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that multi_currency demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.