我需要帮助来定义用户角色。我已经创建了自己的身份验证,并且正在处理自定义授权。但是我需要定义用户角色。我已经创建了我的角色,但我不相信他们对他们应该做什么有任何真正的价值。
用户.rb:
class User < ActiveRecord::Base
has_secure_password
attr_accessible :password_confirmation, :about_me, :feet, :inches, :password, :birthday, :career, :children, :education, :email, :ethnicity, :gender, :height, :name, :password_digest, :politics, :religion, :sexuality, :user_drink, :user_smoke, :username, :zip_code
validates_uniqueness_of :email
validates_presence_of :password, :on => :create
before_create { generate_token(:auth_token) }
ROLES = %w[admin user guest banned]
def send_password_reset
generate_token(:password_reset_token)
self.password_reset_sent_at = Time.zone.now
save!
UserMailer.password_reset(self).deliver
end
def generate_token(column)
begin
self[column] = SecureRandom.urlsafe_base64
end while User.exists?(column => self[column])
end
end