Class: User

Inherits:
ApplicationRecord show all
Extended by:
ActiveHash::Associations::ActiveRecordExtensions
Defined in:
app/models/user.rb

Overview

Devise user.

This model only keeps the information and methods needed for authentication. For user information or role, use UserProfile

Instance Attribute Summary collapse

Has one collapse

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes

Instance Attribute Details

#created_atDateTime

Returns:

  • (DateTime)


255
# File 'db/schema.rb', line 255

t.datetime "created_at"

#current_sign_in_atDateTime

Returns:

  • (DateTime)


249
# File 'db/schema.rb', line 249

t.datetime "current_sign_in_at"

#current_sign_in_ipString

Returns:

  • (String)


251
# File 'db/schema.rb', line 251

t.string "current_sign_in_ip"

#emailString

Returns:

  • (String)


243
# File 'db/schema.rb', line 243

t.string "email", default: "", null: false

#encrypted_passwordString

Returns:

  • (String)


244
# File 'db/schema.rb', line 244

t.string "encrypted_password", default: "", null: false

#last_sign_in_atDateTime

Returns:

  • (DateTime)


250
# File 'db/schema.rb', line 250

t.datetime "last_sign_in_at"

#last_sign_in_ipString

Returns:

  • (String)


252
# File 'db/schema.rb', line 252

t.string "last_sign_in_ip"

#localeString

Returns:

  • (String)


254
# File 'db/schema.rb', line 254

t.string "locale", default: "en", null: false

#nicknameString

Returns:

  • (String)

Validations:



39
# File 'app/models/user.rb', line 39

validates :nickname, presence: true

#remember_created_atDateTime

Returns:

  • (DateTime)


247
# File 'db/schema.rb', line 247

t.datetime "remember_created_at"

#reset_password_sent_atDateTime

Returns:

  • (DateTime)


246
# File 'db/schema.rb', line 246

t.datetime "reset_password_sent_at"

#reset_password_tokenString

Returns:

  • (String)


245
# File 'db/schema.rb', line 245

t.string "reset_password_token"

#sign_in_countInteger

Returns:

  • (Integer)


248
# File 'db/schema.rb', line 248

t.integer "sign_in_count", default: 0

#updated_atDateTime

Returns:

  • (DateTime)


256
# File 'db/schema.rb', line 256

t.datetime "updated_at"

Class Method Details

.for_ichain_username(username, attributes) ⇒ Object



53
54
55
56
57
58
59
60
# File 'app/models/user.rb', line 53

def self.for_ichain_username(username, attributes)
  if user = find_by_nickname(username)
    where(id: user.id).update_all(email: attributes[:email]) if user.email != attributes[:email]
  else
    user = create(nickname: username, email: attributes[:email])
  end
  user
end

.with_role(role) ⇒ Object



49
50
51
# File 'app/models/user.rb', line 49

def self.with_role(role)
  UserProfile.with_role(role).map(&:user)
end

Instance Method Details

#event_emailsActiveRecord::Relation<EventEmail>

Event Emails send by a user

Returns:

See Also:



31
# File 'app/models/user.rb', line 31

has_many :event_emails

#event_organizersActiveRecord::Relation<EventOrganizer>

Event organizer for events

Returns:

See Also:



33
# File 'app/models/user.rb', line 33

has_many :event_organizers

#find_profileObject



45
46
47
# File 'app/models/user.rb', line 45

def find_profile
  profile || create_profile
end

#organizing_eventsActiveRecord::Relation<OrganizingEvent>

Events for which the user is an event organizer

Returns:

  • (ActiveRecord::Relation<OrganizingEvent>)

See Also:



35
# File 'app/models/user.rb', line 35

has_many :organizing_events, through: :event_organizers, source: :event

#profileUserProfile

Setup accessible (or protected) attributes for your model Associated object with all information not directly related to authentication



23
# File 'app/models/user.rb', line 23

has_one :profile, class_name: 'UserProfile'

#reimbursementsActiveRecord::Relation<Reimbursement>

Reimbursements created by the user

Returns:

See Also:



27
# File 'app/models/user.rb', line 27

has_many :reimbursements, inverse_of: :user

#requestsActiveRecord::Relation<Request>

Requests created by the user

Returns:

  • (ActiveRecord::Relation<Request>)

See Also:



25
# File 'app/models/user.rb', line 25

has_many :requests, inverse_of: :user

#state_changesActiveRecord::Relation<StateChange>

State changes (transitions or manual adjustments) performed by the user

Returns:

See Also:



29
# File 'app/models/user.rb', line 29

has_many :state_changes, inverse_of: :user

#titleObject



41
42
43
# File 'app/models/user.rb', line 41

def title
  nickname
end