Minting::Rails is a gem that provides money attributes to ActiveRecord models. It integrates the Minting library into your Rails application.
Add this line to your application's Gemfile:
gem 'minting-rails'And then execute:
bundleAfter intalling generate Minting configuration initializer:
rails g mint:initializerYou can configure the default currency for your application by adding the following line to your config/initializers/minting.rb:
Minting.configure do |config|
config.default_currency = :usd
endTo use Minting::Rails, you add the money_attribute method to your ActiveRecord models. For example:
class SimpleOffer < ApplicationRecord
money_attribute :price, currency: 'USD'
money_attribute :discount, currency: 'USD'
endNow you can use the price attribute as a Money object:
product = Product.ne(price: 100)
puts product.price # => "$100.00"- API Documentation
- Internationalization
- Publish 1.0 Beta
Contribution directions go here.
The gem is available as open source under the terms of the MIT License.