4

I am currently looking for a proper Rails gem for enumerations.

I already tried

  • enum_simulator
  • has_enum

    1. 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)?
    2. Is there a gem out there that can already do this?

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.

2 Answers 2

4

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 enum field has proven complicated in Rails 2.3, trouble with schemas, not sure if it persists in Rails 3.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a lot! i will have a look into it. Do you know if MYSQL compresses the data of a string column if there are a lot of redundant values from the enumeration?
@alex, I don't think so, because that's what enum is for. Don't forget to upvote, by the way.
okay thanks... i will do some further research. i am sorry but i currently dont have enough reputation to do up-votes but i will definitely do it as soon as possible.
I can confirm that MySQL enum is still not supported in Rails 3
0

Look for this gem: enumerate_it. I think it solves your problem!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.