A Rails 3.0 does not do enum database fields? HUH! Really?

IFF someone can point me at the correct tutorial or gem, I’ll eat crow and add a honest apology to this post. Until then, just another rails WTF moment.

Surprise, surprise, surprise.  I went to port a rails 2 set of migrate scripts over to rails 3.0 and it it does not work.

First non-suprise, rails does not natively support enum fields in mysql.

Second non-surprise, nothing actually works for rails 3. So this godsend called rails 3 will cost me days of project productivity to create or port a gem to add enum field support.

Granted, some  miopic engineers created gems that let you hard code the enum values in your active record definition.  Really not good in the real world.  Ya know like when the guy writing Java wants access to your DB.  Then gee, two places where the enum definitions are hard coded.

A couple of gems are just really, really old school. You other grey backs remember when you used to create lookup tables in the DB before enums were natively implemented?

The one that seems to have the best description is  http://rubyforge.org/projects/enum-column/ but it is rails 2. It has to be ported.
The one that is rails 3, but I think it only handles things in the model is https://github.com/jeffp/enumerated_attribute
. I have to investigate this one as well.

https://github.com/electronick/enum_column This one is the winner. It worked. If you are on Rails 2, enum-column.

You GEM guys need a naming convention.  Dash or underscore, PICK ONE.

It is funny, that before I could solve this, I was hit by the fact that rails does not support  foreign keys either.  Happy last century!  For rails 3 use this: https://github.com/matthuhiggins/foreigner.

I seem to do this a lot. Look for something simple. Find what I want is rails 2 and need to be ported, or rails 3 and does not work.  Example, I’ve spend about 6 or so hours getting a rails 3 port of ujs_sort_helper to actually work the way it is advertised.

Rails, the costco of programming environments. Lots of cheap shit that in the end you really did not want.

Here is what I looked at:

gem search enum --remote

*** REMOTE GEMS ***

active_enum (0.9.1)
acts_as_enum (0.1.0)
ar-enums (0.3.6)
attr_enum (0.1.0)
attr_enumerator (0.3.0)
classy_enum (0.8.1)
daeltar-enum_field (0.2.1)
easy_enum (0.2.0)
edave-enumerated_attribute (0.2.18)
enum (1.0.0)
enum_attr (0.0.6)
enum_column (0.1.5)
enum_field (1.0.1)
enum_type (1.0.0)
enumargs (2.0.0)
enumerable-extra (0.1.2)
enumerable-proxy (1.1.4)
enumerable_lz (0.1.1)
enumerable_mapper (1.0.0)
enumerabler (1.0.0)
enumerate_by (0.4.4)
enumerate_it (0.7.4)
enumerated (1.0.1)
enumerated_attribute (0.2.16)
enumerated_state (0.0.7)
enumerations_mixin (0.2.1)
enumlogic (1.0.3)
has_enum (0.7.3)
has_enumeration (1.0.2)
haz_enum (0.5.1)
in_enumerable (1.0.0)
in_memory_enumeration (0.3.0)
LazyEnumerable (0.0.4)
markcatley-enum_field (0.2.0.1)
menumatic (0.2.0)
nice-enum (0.1.3)
nice_enum (0.1.3)
object-in-enumerable (1.1.0)
objectreload-simple_enumerations (0.1.6)
pg_enum (0.2.0)
rap_enum (0.0.2)
rap_enumerable (0.0.1)
renum (1.3.1)
robot_enumerable (0.1.0)
sga_enum (0.1.0)
simple_enum (1.3.2)
simple_enumerations (0.1.1)

About mpechner

I am a software engineer who like to build tools to help make other engineers lives easier. I am ham radio operator, call sign NE6RD. I am a kit building fiend at times. solder smoke is good. Finally putting the my Arduino kits to good use.
This entry was posted in rails, Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s