Store mixed numbers in an ActiveRecord model seamlessly with built-in validation.
Add this line to your application's Gemfile:
gem 'mixed_number_rails'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mixed_number_rails
rails_mixed_number is based on my general purpose mixed_number ruby gem. Go there for examples on using MixedNumber objects.
- Create a model with a decimal attribute
? rails g model Item amount:decimal
- Open the model file you just generated and add
mixed_number_attribute
with the name of your attributeclass Item < ActiveRecord::Base mixed_number_attribute :amount end
- Your attribute will now be a mixed number, with validation.
- Fork it ( https://github.com/tpadjen/mixed_number_rails/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request