All our projects have enum-like requirements like this:
<select>
boxes.Most of the time, this requirement is also needed:
In our past projects there are many different solutions for these related requirements, e.g. ChoiceTrait
, methods like available_states
, helper methods to render option tags, and so on. Unfortunately each of these solutions is limited in its own way, so it was time to come up with a standard solution.
We have now updated/created two gems that implement the requirements above using the best practices we know of:
Power
instead of in an ActiveRecord model.This is the way we want to implement the requirements above in most of our future projects. You should migrate existing projects to assignable_values if you run into the limits of our previous approaches (e.g. ChoiceTrait
cannot be internationalized).
Please read the assignable_values README Show archive.org snapshot to familiarize yourself with the new solution.
Also see our instructions on how to migrate legacy approaches to assignable_values.
There is a custom RSpec matcher.