How to add admin to Devise in Rails / Mongoid user class?
I have a User in Rails class using Mongoid and Devise. I can't figure out how to add the admin role. How To On platformtec (Devise) site, I want to run a standard Rails migration, but that doesn't work because of Mongoid.
Can anyone point me in the right direction?
Here's my user.rb (minus 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
+3
source to share
1 answer
You just need to add the field admin
to Boolean so that in your User class add this line:
field :admin, :type => Boolean, :default => false
this is exactly the same migration to AR:
class AddAdminToUsers < ActiveRecord::Migration
def self.up
add_column :users, :admin, :boolean, :default => false
end
def self.down
remove_column :users, :admin
end
end
After this addition, the whole admin method in the wiki designer works fine.
+3
source to share