app/models/user.rb in wheels-0.0.17 vs app/models/user.rb in wheels-0.0.18
- old
+ new
@@ -1,26 +1,26 @@
class User < ActiveRecord::Base
before_create :create_profile
belongs_to :role
-
- # Include default devise modules. Others available are:
- # :token_authenticatable, :confirmable, :lockable and :timeoutable
- devise :database_authenticatable, :registerable, :confirmable, :token_authenticatable,
- :recoverable, :rememberable, :trackable, :validatable
-
- def self.super_user
- @@super_user ||= User.where(:role_id=>Role::SUPER).first
- end
-
has_many :blogs, :dependent => :destroy
has_one :profile, :dependent => :destroy
has_many :galleries, :dependent => :destroy
def create_profile
self.profile ||= Profile.create(:user => self)
end
+ def role?(role)
+ if role.kind_of?(Role)
+ return role==self.role
+ elsif role.is_numeric?
+ return self.role_id==role
+ else
+ return self.role.name.underscore==role.underscore
+ end
+ end
+
def role=(role)
if role.kind_of? Role
self.role_id = role.id
else
role = role.to_s.camelize
@@ -35,10 +35,15 @@
def confirm!
self.confirmed_at = DateTime::now
save
end
+ # Include default devise modules. Others available are:
+ # :token_authenticatable, :confirmable, :lockable and :timeoutable
+ devise :database_authenticatable, :registerable,
+ :recoverable, :rememberable, :trackable, :validatable,
+ :token_authenticatable, :confirmable, :lockable, :timeoutable
+
# Setup accessible (or protected) attributes for your model
- attr_accessible :email, :password, :password_confirmation,
- :blogs, :profile, :role, :galleries
+ attr_accessible :email, :password, :password_confirmation
end