Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Patricio Sanchez
/
quiniela-mundial
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Iker Narvaez
2018-06-08 17:44:05 -0500
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
333efd786404325f8fdfb8f0860c818f5f2f261a
333efd78
2 parents
8224ee4a
d770a636
Merge branch 'master' of git.ukko.mx:psanchezp/quiniela-mundial
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
0 deletions
app/controllers/application_controller.rb
app/models/bet.rb
app/models/user.rb
app/controllers/application_controller.rb
View file @
333efd7
...
...
@@ -2,5 +2,23 @@ class ApplicationController < HeimdallEngine::ApplicationController
protect_from_forgery
with: :exception
def
root
@leaderboard
=
check_leaderboard
@upcoming_matches
=
check_matches
@results
=
check_results
end
private
def
check_leaderboard
User
.
all
.
order_by
(
&
:user_score
).
take
(
5
)
end
def
check_matches
Match
.
active
.
order
(
date: :ASC
).
limit
(
5
)
end
def
check_results
return
[]
unless
@current_user
@current_user
.
bets
.
join
(
:matches
).
order
(
match:
{
date: :ASC
}).
limit
(
5
)
end
end
...
...
app/models/bet.rb
0 → 100644
View file @
333efd7
#
class
Bet
<
ApplicationRecord
validates
:score_local
,
:score_visit
,
presence:
true
belongs_to
:user
,
inverse_of: :bets
scope
:active
,
->
{
joins
(
match: :pool
).
where
(
pools:
{
active:
true
})
}
end
app/models/user.rb
View file @
333efd7
...
...
@@ -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'
)
...
...
Please
register
or
login
to post a comment