implement simple wall of shame
This commit is contained in:
parent
3530fd1e5d
commit
24f8050ac9
3 changed files with 17 additions and 5 deletions
|
@ -3,7 +3,11 @@ class Statistics < Rails::Application
|
|||
|
||||
def shameful_users
|
||||
User.where('balance > :amount', amount: config.shameful_balance)
|
||||
.order(:balance)
|
||||
.order(balance: :desc)
|
||||
end
|
||||
|
||||
def total_debt
|
||||
User.where.not(id: User.zeus).where('balance > 0').sum(:balance)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -8,6 +8,14 @@
|
|||
%h2 Cute Little Statistics
|
||||
%p None here yet.
|
||||
%h2 Wall of Shame
|
||||
%ul
|
||||
- @statistics.shameful_users.each do |user|
|
||||
%li="Shame on #{user.name}!"
|
||||
%table
|
||||
%thead
|
||||
%th People who should be ashamed
|
||||
%th Part of total debt to Zeus
|
||||
%tbody
|
||||
- @statistics.shameful_users.each do |user|
|
||||
%tr
|
||||
%td= "Shame on #{user.name}"
|
||||
// Won't divide by zero because there won't be any users with
|
||||
// a shameful debt if the total debt is zero.
|
||||
%td= "#{100 * user.balance / @statistics.total_debt}%"
|
||||
|
|
|
@ -24,6 +24,6 @@ module Tab
|
|||
config.active_record.raise_in_transactional_callbacks = true
|
||||
|
||||
# Which is the lowest balance you should be ashamed of.
|
||||
config.shameful_balance = 50
|
||||
config.shameful_balance = 50 # In eurocents!
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue