2014-07-28 14:15:08 +03:00
|
|
|
class User < ActiveRecord::Base
|
|
|
|
# Include default devise modules. Others available are:
|
|
|
|
# :lockable, :timeoutable and :omniauthable
|
|
|
|
devise :database_authenticatable, :registerable, :confirmable,
|
|
|
|
:recoverable, :rememberable, :trackable, :validatable
|
2014-08-30 17:31:29 +03:00
|
|
|
|
2014-08-07 14:05:13 +03:00
|
|
|
has_one :speaker_profile
|
2014-08-30 17:31:29 +03:00
|
|
|
has_many :lectures
|
|
|
|
has_many :workshops
|
2014-09-30 13:34:09 +03:00
|
|
|
has_many :events
|
2014-08-31 14:57:34 +03:00
|
|
|
|
|
|
|
accepts_nested_attributes_for :speaker_profile, update_only: true
|
2014-09-17 17:48:46 +03:00
|
|
|
|
2014-09-18 01:07:09 +03:00
|
|
|
default_scope { order id: :desc }
|
|
|
|
|
2014-10-10 19:23:38 +03:00
|
|
|
def name
|
|
|
|
speaker_profile.try(:name) || email
|
|
|
|
end
|
|
|
|
|
2014-09-17 17:48:46 +03:00
|
|
|
def toggle_admin!
|
|
|
|
update admin: !admin
|
|
|
|
end
|
2015-05-25 11:41:11 +03:00
|
|
|
|
|
|
|
def profile_picture
|
|
|
|
if speaker_profile.present?
|
|
|
|
speaker_profile.picture
|
|
|
|
else
|
|
|
|
PictureUploader.new
|
|
|
|
end
|
|
|
|
end
|
2014-07-28 14:15:08 +03:00
|
|
|
end
|