psanchezp

User score

......@@ -26,6 +26,8 @@ class User < ApplicationRecord
before_save :encrypt_password
has_many :bets, inverse_of: :user
has_and_belongs_to_many :roles, inverse_of: :users,
class_name: 'HeimdallEngine::Role',
join_table: 'users_roles',
......@@ -33,6 +35,10 @@ class User < ApplicationRecord
association_foreign_key: "role_id"
def user_score
bets.active.sum :points
end
def encrypt_password
return unless password.present?
self.password_salt = BCrypt::Engine.generate_salt.force_encoding('UTF-8')
......