I am currently looking for a proper Rails gem for enumerations.
I already tried
- enum_simulator
-
- Both use a string column in the database to store the enum data.
Wouldn’t an integer column have a better performance or less storage consumption (using MySQL)? - Is there a gem out there that can already do this?
- Both use a string column in the database to store the enum data.
Thanks a lot!
Update:
I found the simple_enum gem which uses integer values to represent the enum within the database. It supports rails 3.1 and is well maintained.
Ruby Toolbox is your friend. https://www.ruby-toolbox.com/categories/Active_Record_Enumerations
I’ve been using enumerated_attribute with both Rails 2.3 and Rails 3 with good results. Yes, it uses a string column.
IMO string columns are better than integer columns because they don’t imply any order of values, and make the attribute easier to understand (reverse engineer, if you want to) without looking at the source code. And usually the performance difference is negligible, especially if you have an index on the field – and you should.
Using the MySQL
enumfield has proven complicated in Rails 2.3, trouble with schemas, not sure if it persists in Rails 3.