Orbit/app/models/user/user.rb

30 lines
910 B
Ruby
Raw Normal View History

class User
include Mongoid::Document
2011-03-08 09:25:46 +00:00
include Mongoid::Timestamps
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable
mount_uploader :avatar, AvatarUploader
2011-01-31 03:31:33 +00:00
field :admin, :type => Boolean, :default => true
2011-11-18 08:43:14 +00:00
field :active_role
has_many :attribute_values, :autosave => true, :dependent => :destroy
belongs_to :role
belongs_to :sub_role
accepts_nested_attributes_for :attribute_values, :allow_destroy => true
2011-11-17 12:02:58 +00:00
def name
infos = self.user_infos.detect {|info| info.key.to_s.eql?('profile') }
if infos
first_name = infos.attribute_values.detect {|value| value.key.to_s.eql?('first_name') }[I18n.locale.to_s] rescue nil
2011-11-19 19:16:35 +00:00
last_name = infos.attribute_values.detect {|value| value.key.to_s.eql?('last_name') }[I18n.locale.to_s] rescue nil
2011-11-17 12:02:58 +00:00
return "#{first_name} #{last_name}"
else
return nil
end
end
end