Rails 4.1 Cannot Get All Enum Types

I just upgrade my application to rails 4.1.0.beta1

I have a class

class User < ActiveRecord::Base
    enum usertype: { :employee => 10, :boss => 30, :manager => 40, :admin => 50 }
}

Does the whole enumeration function work well, like user.boss? # ture

But when I try to get all types of users using

User.usertypes

I have an undefined method for "usertypes"

Any help?

This is the link I learned from http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html

Edit: Migration

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :email
      t.string :password_digest
      t.string :remember_token
      t.boolean :is_locked
      t.integer :usertype, default: 10
      t.timestamp :last_login_at

      t.timestamps
    end
  end
end
+3
source share
1 answer

Are the correct migrations created?

The enum attributes are values ​​that map to integers in the database, but can be requested by name.

, , " " "". ?

1:

, , Rails 4.1.0.beta1, edge Rails. , -...

2:

, , Rails 4.1.0.beta1 . User::USERTYPE .

+3

All Articles