I have a class User in Rails using Mongoid and Devise. I can’t seem to figure out how to add an Admin role. The How To on the platformtec (Devise) site wants me to run a standard Rails migration, but that’s not working because of Mongoid.
Can anyone point me in the correct direction?
Here’s my user.rb (minus the modules commented out):
class User
include Mongoid::Document
# Include default devise modules.
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
## Database authenticatable
field :email, :type => String, :null => false, :default => ""
field :encrypted_password, :type => String, :null => false, :default => ""
## Recoverable
field :reset_password_token, :type => String
field :reset_password_sent_at, :type => Time
## Rememberable
field :remember_created_at, :type => Time
## Trackable
field :sign_in_count, :type => Integer, :default => 0
field :current_sign_in_at, :type => Time
field :last_sign_in_at, :type => Time
field :current_sign_in_ip, :type => String
field :last_sign_in_ip, :type => String
## Token authenticatable
# field :authentication_token, :type => String
field :name
validates_presence_of :name
validates_uniqueness_of :name, :email, :case_sensitive => false
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
end
Thanks,
Charlie Magee
You just need add an
adminfield in Boolean so in your class User add this line :it’s exactly the same this migration in AR:
After this adding, all method about admin in the devise wiki works fine.