PreferĂȘncias
This gem is an extraction of the Spree Ecommerce Open Source Software.
I couldn't find anything as robust as their solution so I decided to extract it into a gem.
Installation
Add this line to your application's Gemfile:
gem 'preferencias'
And then execute:
$ bundle
Or install it yourself as:
$ gem install preferencias
Run migrations
$ rails generate preferencias:migration
$ bundle exec rake db:migrate db:test:prepare
Usage
class YourModel < ActiveRecord::Base
serialize :preferences # create a column as text in your database
preference :color, :string, default: 'red'
preference :number_of_pokemons, :integer, default: 151
end
@model = YourModel.create(preferences: {number_of_pokemons: 649})
@model.preferred_number_of_pokemons # => 649
@model.preferred_color # => "red"
Contributing
- Fork it ( https://github.com/davidslv/preferences/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