Soldiers lost

This commit is contained in:
Andrew Tomaka 2015-04-28 10:19:46 -04:00
parent 1683f24c55
commit e20c54fed4
3 changed files with 14 additions and 3 deletions

7
app.rb
View file

@ -31,10 +31,11 @@ post '/' do
end
end
get '/bossfight/:username' do
username = params['username'] ? params['username'] : 'mafiaman'
user_raids = Raid.for_user(username)
get '/bossfight/?:username' do
@username = params['username'] ? params['username'] : 'mafiaman'
user_raids = Raid.for_user(@username)
@first_negative = user_raids.first_negative
@soldiers_lost_to_date = user_raids.soldiers_lost_to_date(@first_negative.created_at)
erb :bossfight
end

View file

@ -16,4 +16,8 @@ class Raid < ActiveRecord::Base
def self.first_negative
where('money < 0').order(:created_at).first
end
def self.soldiers_lost_to_date(date)
where('date < ?', date).sum(:soldiers)
end
end

View file

@ -1,3 +1,9 @@
<h2>Bossfight: <%= @username %></h2>
<% if @first_negative %>
Raider who broke the walls: <%= @first_negative.attacker %><br/>
<%end%>
<% if @soldiers_lost_to_date %>
Soliders killed before walls broken: <%= @soldiers_lost_to_date %>
<% end %>