Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is incompatible with rails 4.2 #25

Open
harsimranmaan opened this issue Jan 16, 2015 · 4 comments
Open

This is incompatible with rails 4.2 #25

harsimranmaan opened this issue Jan 16, 2015 · 4 comments

Comments

@harsimranmaan
Copy link

enum_column3-0.1.4/lib/enum/enum_adapter.rb:30:in block in <top (required)>': undefined methodtype_cast' for class `ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::Column' (NameError)

@harsimranmaan harsimranmaan changed the title This is imcompatible with rails 4.2 This is incompatible with rails 4.2 Jan 16, 2015
@trivektor
Copy link

It looks like this issue has been fixed on master but the update has not been released to rubygems.org yet. You can just point to the source in your Gemfile and install it to get the fix.

@Lambenttelos
Copy link

I am having trouble on rails 4.2 still. A fix I found would be to move the alias lines below the methods they are aliasing in enum_adapter.rb.

@schuylr
Copy link

schuylr commented Aug 20, 2015

@Lambenttelos This doesn't work. By moving the aliasing after the override definitions, you're just aliasing the newly declared methods. Your columns will have a type of :string and you'll get a string instead of symbols. This is a silent failure.

The break in Rails 4.2 is because of this refactoring and other subsequent updates by @sgrif - instead of defining the type using simplified_type, it's now set up in ActiveRecord::ConnectionAdapters::Mysql2Adapter using initialize_type_map. You also have to declare a new ActiveRecord::Type::Enum class to convert the values to and from the database, and return a proper :enum type for ActiveRecord to handle.

I've made all of these changes in https://github.com/jewlr/enum_column for those who are interested. The code should also be backwards compatible down to Rails 3.

@Lambenttelos
Copy link

@schuylr Thanks for the update! I just took a novice guess at it and yeah that one change I suggested would have just changed where I would have run into errors then. With the project I was updating at the time we just decided to rip out the gem and use the built in enum functionality that is in active record now which was easy for us as our use case was simple. We have some other projects that are not so simple and this fix should save some headaches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants