Mayank Mayank - 1 year ago 69
Ruby Question

undefined method `enum' for #<Class:0x007f099c303390>

I am using in rails and getting following error:

undefined method `enum' for #<Class:0x007f03202a1190


class Location < ActiveRecord::Base

enum status: [ :current, :preffered ]


How can i remove this error.

Answer Source

ActiveRecord::Enum was only introduced to Rails at commit db41eb8a, and so far this commit has only been released with Rails tag v4.1.0.beta1.

It's likely that the current Rails gem you're using does not yet have this commit, and so does not have the code for implementing enum.

To check to see which version of the Rails gem you have, run:

bundle show rails

I just ran bundle update and then bundle show rails, and I am showing:

[PATH TO YOUR GEMS]/rails-4.0.2

This version of the gem does not include the code with enum. You can see this by comparing what is in v4.0.2 with what is in v4.0.1.beta1. If you click on 'File Changed' and then do a search in the page for enum.rb, you'll see that that is completely newly added code.

If you want to ensure that you get the newly tagged version of Rails, you can modify your Gemfile so that your line for including rails looks like this:

gem 'rails', :git => 'git://', :tag => 'v4.1.0.beta1'

After you do a bundle update, you can see by doing a bundle show rails that you have the following rails gem:

[PATH TO YOUR GEMS]/rails-f706d5f945c5

f706d5f945c5 is the commit that was tagged for release v4.1.0.beta1.

After you get this bleeding edge version of the Rails gem, you should have access to this enum functionality.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download