So, I serialize stuff into arrays in my AR objects where it doesn't make sense to go through the rigamaroe of actually making an empty AR model to use for the association. This is just a bit of glue to make using that pattern a bit easier with
There's not much to this thing, and what's there exists only to serve the needs that I've had for this sort of thing.
That said, pull requests are totally welcome :)
gem install collectable
# Gemfile
gem 'collectable'
The short version is "include the module and define some characteristics." That's also the long version, as it were.
class HairColor
include Collectable
characteristic :blonde
characteristic :brown
characteristic :red
characteristic :black
characteristic :purple
characteristic :tie_dye
end
Then, to actually use the thing, do something like this in your view:
<%= form_for @person do |f| %>
<%= f.collection_check_boxes(:hair_color, HairColor.collected, HairColor.value, HairColor.name) %>
<% end %>
Do you use git-flow? I sure do. Please base anything you do off of the develop branch.
- Fork it.
- Perform some BDD magic. Seriously. Be testing.
- Submit a pull request.
- 0.0.4 - Renamed "traits" to "characteristics"
- 0.0.3 - .value and .name actually added
- 0.0.2 - Renamed collected_item#val to collected_item#value
- 0.0.1 - Public release
MIT License. Copyright 2014 Dennis Walters